Thursday, October 26, 2006

Incorrect behavior of window.onblur event under IE and a workaround

<html>
<header>
<script>
/*
In Internet Explorer window.onblur event is implemented incorrectly (as opposed to Firefox/Mozilla browsers). It is wrongly fired when focus is switched between HTML elements *inside* a window.
Suppose you're trying to automatically close a popup window when focus is switched to another (main) window (a common task). As a result of the described bug, clicking on any element *inside* a popup window or trying to select something there will also close a popup.
http://codingforums.com/showthread.php?p=500127
Below is a workaround.
*/


var active_element;
var bIsMSIE;

function initiateSelfClosing() {
if (navigator.appName == "Microsoft Internet Explorer") {
active_element = document.activeElement;
document.onfocusout = closeWnd;
bIsMSIE = true;
}
else { window.onblur = closeWnd; }
}

function closeWnd() {
if (window.opener != null) {
if (bIsMSIE && (active_element != document.activeElement)) {
active_element = document.activeElement;
}
else {
window.close();
}
}
}

</script>
</header>

<body onload="initiateSelfClosing()">

Your stuff

</body>
</html>

Friday, September 29, 2006

jQuery and an example: Dynamic Stylesheet Switcher

I've just found a fantastic JavaScript library called jQuery.
jQuery is a Javascript library that takes this motto to heart: Writing Javascript code should be fun.

Here's a cool example of using it: Dynamic Stylesheet Switcher.

Levels of JavaScript Knowledge

Dean Edwards rules! Look at the comment #77, though :)

I understand level 5, but I don't know yet why

var button = document.getElementById("hello");
button.addEventListener("click", function(event) {
hello(WORLD);
}, false);

is better than

var button = document.getElementById("hello");
button.onclick = function() {
hello(WORLD);
};

Could someone explain it?

Sunday, August 27, 2006

BIG BALL OF MUD

Looks familiar, doesn't it?

ASP.NET 2.0: Cross Page Postbacks

Most regular Web pages written by professional developers in ASP, PHP or other conventional languages use HTTP POST operation for submitting data from one page to another, often hidden page which manages data submission and normally updates a database. It was considered to be a bad practice to POST to the same page. First of all, it leads to inability to use browser's Reload/Refresh button (you would get "Page expired" message) unless some special manipulations with cache are performed. Also, it potentially leads to multiple modifications of a database in case Reload was performed.
ASP.NET introduced a paradigm of POSTing to a same page as a main method. It used internal tricks to deal with "Page expired" and multiple data updates. In my opinion, it was teaching newbie developers, who didn't realize what happens under the hood to a bad technique. (Not a first time MS is doing that, though).

It looks like obvious considerations started to overturn strange ideas of MS Web designers - thus "Cross Page Postbacks" are introduced in ASP.NET 2.0. Most of experienced Web developers who are not inclined to a weird Microsoft's idea of transforming page-based architecture of World Wide Web to Windows desktop applications behavior used it all the time in most Web languages...

Tuesday, August 22, 2006

ASP: Server.Execute vs. server-side includes

I suddenly realized on advantage Server.Execute() command has over server-side includes in a classic ASP: Server.Execute() is a part of normal execution flow and thus works as a conditional include. There is no normal way to include files conditionally with <!--#include file [or virtual]="_our_file.asp"-->, because those includes are treated with something like ASP preprocessor. On the other hand, local variables declared in calling file are available inside include and are not available in executed file - that's one reason I never used it.

VB.NET vs. C#

1) Is it right that anything which could be done with C# could be (as easy and elegant) done in VB.NET?

2) What programmers are easier to find on a market, VB.NET or C#? Which out-of-school (university) programmers are easier to find, VB.NET or C#?

3) Which programmers tend to get more money, C# or VB.NET?

Tuesday, August 15, 2006

ASP.NET 2.0 Demo/Test Playground

I've just launched my ASP.NET 2.0 Demo/Test Playground

FireFTP

FireFTP is a very convenient FTP client program: it runs directly from your Firefox browser and is organized very well. It's my favorite now.

Monday, August 07, 2006

Bookmark synchronization

I finally found a working software for bookmark synchronization across separate computers. Bookmark Sync and Sort This add-on works with Mozilla Firefox and allows to upload your bookmarks to FTP address of your choice (I use a directory on my domain) and to download them to another machine. I just synchronized bookmarks on my machine here with my home Firefox. I also found another software which allows to synchronize bookmarks (favorites) across many different browsers on a single machine http://www.syncbookmarks.com/ (they are planning to add FTP and http://del.icio.us/ synchronization later on). So, together this add-on and this application allowed me to synchronize bookmarks on all browsers at home and on my Firefox at work!

Update, July 25, 2008: Unfortunately, neither "Bookmark Sync and Sort" plugin nor Syncbookmarks application work with Firefox 3. Syncbookmarks does not report any error, but doesn't pick Firefox's bookmarks. I'm switching from to a new and powerful Foxmarks plugin. It works beautifully in a fully automated mode. A version for IE is going to be released. To sync bookmarks for SeaMonkey or Opera you can use Foxmarks for Firefox and Internet Explorer in a combination with Syncbookmarksto to copy IE favorits into SeaMonkey or Opera bookmarks. (I always use Firtefox as a main bookmark source.)

Friday, August 04, 2006

Folksonomy

More and more often I have a feeling that Web-related knowledge increases in a chain reaction manner and I'm falling behind. Thanks to Internet, Tim Berners-Lee, and Google but... how to cope with it?
Did you here about Folksonomy and Tag Clouds?

Wednesday, August 02, 2006

Interview with Jakob Nielsen, a world athority in Web usability

Matt Mickiewicz interviews Jakob Nielsen, author of the brand new book "Prioritizing Web Usability," about AJAX, usability's close link to keyword advertising, and some of the advertising formats we're seeing around the Web today.

Monday, July 31, 2006

Brothercake

Here's a fantastic JavaScript site. Look at his Ultimate Drop Down Menu! I have his book but haven't started to read it :(

Saturday, July 15, 2006

AJAX File Uploader

In an administrative interface of my Photo Gallery I'm using XMLHttpRequest to send all the information about picture being uploaded to a server and check its validity. (I used synchronous mode because at the time I programmed it all the AJAX heap wasn't there yet). I wanted to upload files with the help of XMLHttpRequest without page reloading, but I couldn't find a way to do that. There were some proprietary IE solutions and proprietary Mozilla solutions, but no common one. To upload file, HTML form must set ENCTYPE="multipart/form-data" (a default value is "application/x-www-form-urlencoded") and it seems that XMLHttpRequest cannot do that.
The solution I found was to check everything and send a data to server using XMLHttpRequest without page reloading, then to upload a picture using conventional FORM POST operation inside an IFRAME.
It looks like that there is nothing new that and this Indian guy uses similar approach with his "AJAX File Uploader" class.

Although.... let's investigate all results of corresponding Google search.

Friday, July 14, 2006

TestDrive
I created a new sub domain for learning and testing new [Web] technologies. I will add some examples of using various Web-related technologies there.
http://testdrive.kelman-all.com/

I'm starting to educate myself with an unusual strength :) I fell behind once again.

******************
JavaScript - version 1.7 is about to be released
http://developer.mozilla.org/en/docs/New_in_JavaScript_1.7

The cool feature of JavaScript is that it allows to check if a function is defined and create your own version otherwise, adding it to a prototype of an object. For example, JavaScript's String object lacks trim() method. http://www.developingskills.com/ds.php?article=jstrim&page=1 shows how to fix it.

Yesterday I found a cool library which implements new 1.6 -1.7 methods of arrays in a similar manner: when your browser's JavaScript will become 1.6 and then 1.7 your code won't break, but will automatically use built in methods instead of custom ones.
http://4umi.com/web/javascript/array.htm

********************
AJAX - it's a pleasure! It's a coming way of making really interactive Web applications which communicate with a server without page reloading. There are plenty of books on this issue (and I bought almost all of them) but one really stands apart: Ajax Design Patterns by Michael Mahemoff
His site is http://ajaxpatterns.org/.

********************
PHP. Version 5 is a full-fledged OOP language with a lot of convenient and powerful libraries developed for it. You normally can do anything you can do in ASP.NET, for example, but in a much easier and more flexible way. I was surprised when I started to work with PHP on how much better, bigger, and more convenient is its standard library and common user-developed libraries than ones used in ASP. Open Source rules!

I'm going to learn and pass Zend PHP Certification http://www.zend.com/store/zend_php_certification

********************
Design Patterns
It's a cool thing, if you learn it with an excellent Head First Design Patterns (thank you, Andrew, for pointing me to it) written by by Elisabeth Freeman and Eric Freeman

*********************
MySQL 5.1 and PostgreSQL - I need to jump into that.

*********************
.NET
I still need to get heavily involved into ASP.NET and C# development. While I like C#, I think that ASP.NET approach suffers greatly from usual Microsoft's design flaw: it's too big, it's too predefined, so when you develop a real application you spend more time on finding workarounds for built-in events and other features which work the way they were designed, but not the way your application's business logic dictates.

Thursday, July 06, 2006

Eric's weblog - Will Ajax get another bad rap? Yahoo worm

Here's an interesting set of articles about Ajax security ("Samy worm").

Also, Eric showes there a workable soliution for implementing timeout warnings for session expiration.

Javascript Closures

Javascript Closures - an article by jibbering.com.

Closures and IE Circular References and What makes closures interesting?

Wednesday, July 05, 2006

How to implement timeout warnings for session expiration?

Hi everybody!
My bank's Web site has a neat feature: after some period of user inactivity it displays a JavaScript confirmation window asking to click a button to stay connected. If user clicks a button within some short time interval, he/she stays connected. Otherwise, after closing a confirmation window user is forcefully redirected to logout screen.

I think it's a nice user-friendly feature. It's too often when users of my ASP applications enter a bunch of data to a form, then went somewhere, return and click on a "Submit" button just to realize that session was already expired and all data entered was lost.

Question: how to implement that feature (wit ASP or PHP back-ends)?
ASP provides Session_OnEnd event (PHP does not), but it gives no help: I don't think you can refresh a session at the time this event is fired, and you cannot interact with user from inside this event handler.
I can imagine running JavaScript timer on each page. When it decides that session is about to expire, it displays a warning. In case user says he wants to continue, JavaScript connects to a server using XMLHttpRequest and runs some script there, which automatically resets a session expiration time. A response from a server should tell JavaScript to reset a timer.
But what if there are more than one browser window, frame, or iframe open for this site? Especially for multiple windows we need a way for server to initiate counter reset on all client windows when one of them is refreshed. (By the way, it isn't implemented correctly on my bank's website). We could make one more XMLHttpRequest to a server just before displaying a coming expiration warning. It will ask a server for actual expiration time and reset this window's timer as necessary. But for server to know expiration time it must be reset during each page server script running and saved ... in a session variable.
Another solution which comes to mind would be to use server-push technology to reset all necessary client timers. There are some interesting news about it there.

It would be nice to implement timer on a server instead of client JavaScript... but I have no idea of how to do it in ASP or PHP.

What do you think about all that?

Monday, April 17, 2006

The World Wide Web Consortium’s (W3C) new Web API Working Group has released a working draft of the official specification for the XMLHttpRequest obje

As Kevin Yank said in his BLOG entry at SitePoint
The World Wide Web Consortium’s (W3C) new Web API Working Group has released a working draft of the official specification for the XMLHttpRequest object, which is at the heart of AJAX.

Wednesday, April 05, 2006

How to install Zend Server on both IIS and Apache

1. Install Zend Client.
2. Install Zend Server on Apache. Point to it's associated copy of php.ini (PHP 5 in my case).
For Apache to work with a particular php.ini, httpd.conf should contain a line
PHPIniDir _path_to_php.ini without file name and trailing slash; like"C:/phpini/php5".
For Apache to work simultaneously with IIS servers must listen to different ports.
3. Make a copy of Program Files\Apache Group\Apache2\htdocs\ZendStudioServer folder.
4. Run Zend Server installer again. It will uninstall itself. Choose to keep php.ini (and httpd.conf) files.
5. Run Zend Server installer and choose to install it on IIS.
For IIS to use a particular copy of php.ini file, PHPRC environmental variable should be added and pointing to php.ini file; like"C:/phpini/php4".
6. Take a copy of Apache Group\Apache2\htdocs\ZendStudioServer folder which you created on step 3 and replace actual folder (which was changed during uninstallation of Zend Server from Apache). Restart Apache.
7. Modify Start Menu links if necessary, to point to Zend Server on correct ports.

Note: if for some reason your php.ini file has a line describing ZendOptimizer and that version of Optimizer is not installed, Zend Server or Zend Optimizer installer will complain about it during installation. Just ignore it: a latest Optimizer will be installed and php.ini corrected.

Note:Installing Zend Server on IIS first and on Apache second will lead to inability to run it under IIS.

That's it.

Thursday, March 30, 2006

onBeforeUnload event

As most of people I thought that onBeforeUnload event is not supported by Mozilla browsers because it contradicts to purists view on how Internet page should behave. But it turned out that I'm wrong! Even people from Mozilla developers team recognized an importance of this event for Web Application (do not mix this term with a regular Web page). For example it allows to ask user if he wants to leave a page without saving a modified data. Even more, it allows to stay on a page until user agrees to leave.
However, Microsoft in its usual intentional ignorance of the fact that more and more people using other browsers (Firefox/Mozilla) provides a proprietary non-standard example of using onBeforeUnload event on their page. And most people still follow that bad approach and think that only IE supports this feature.
That's wrong! Here's an example which works with Mozilla/Firefox as well! Please try it and think if it could be helpful to use on your company's web site.

Monday, March 20, 2006

Adding trim functions to the JavaScript String object

"The String object in JavaScript contains several powerful methods for manipulating strings. Strangely, though, it doesn't contain any methods that readily permit the removal of whitespace from the beginning or end of a string..." URI

Saturday, February 25, 2006

Alice and Bob - archetypal characters

I was reading Wikipedia article about Public-key cryptography and suddenly noticed "Alice and Bob - a commonly used placeholders for archetypal characters"
Isn't it nice and funny?

Monday, January 09, 2006

Axiom: In HTTP, GET must not have side effects.

Alex Bosworth's Weblog: Google's new web accelerator breaks webapps
Univeral Resource Identifiers -- Axioms of Web architecture

I knew it for a long time - learned a hard way. But how often you see ASP pages which include statements modifying database data in visible pages - pages containing HTML, how often you see such pages being linked from other pages! It's a GET operation when you follow a link!
Moreover, one thing which I don't like in ASP.NET (and it's a common tendency for Microsoft's products for developers) is that it tends to hide everything. There is no server and client, everything is mixed together into web controls. I don't need to know if it POSTs or GETs or is just sitting on a client in JavaScript. In my experience, such attempts always fail: to program something meaningful you have to now inner details.

Sunday, January 08, 2006

Hijax:

DOM Scripting: Hijax
Adactio: Journal - Progressive enhancement with Ajax

I like this idea of "progressive enhancement and graceful degradation" using a modular server-side architecture "capable of returning entire pages or portions of pages"! It's clear and doable!
Basically, you need to write a set of functions or maybe a class with a set of functions running on a server and then have one page [with server side script and no html] which handles a normal form POSTs using a set of those functions, and other pages which handle xmlhttp request post/get submissions by using an appropriate subset of the same functions. It could be even the same page which behaves differently depending on who and how calls it. A kind of Web Service :)
This page then either redirects to an appropriate HTML page, or just sends an appropriate XML or text back to AJAX caller.

Saturday, January 07, 2006

Dynamic web applications and disabling browser's "Back" and "Forward" buttons.

Introduction:
I have recently read several good articles talking about problems with browser's "Back" and "Forward" buttons on AJAX, and, speaking in more general terms, any web pages with a dynamic content. Basically: when user clicks one of these buttons browser loses document's state. So, it is not possible to go back. It's perfectly described in isolani's article.

It's a long known problem with pages with frames, dynamic PHP/ASP pages using session variables, etc. People discuss various possibilities to save a state in browser's history/cache and for AJAX commands to add entries into history/cache. I believe that as this problem has only one radical solution: a web browser should allow HTML document to conditionally disable "Back" and "Forward" buttons.
Such dynamic web pages are not plain but rather web applications - speaking in isolani's terms. And an old web ideology which restricts from doing that does not apply to such pages.
Not everybody knows that Internet Explorer already allows to control these buttons in a indirect way with its onbeforeunload() event.

Again, here are several articles when people desperately try to resolve these issues:
Fixing the back button that AJAX broke
Hijax
Back button and Undo in Ajax applications
public-webapi@w3.org - Ajax Back/Forward History problem – saving document state

I sent a couple of messages in reply to this lists.w3.orgdiscussionn - not sure when and where they will appear. So, below is a copy of these messages:

***************
In reply to Karl Pongratz's message I said the following:

Karl Pongratz wrote:
> I also want to note that I wanted to propose something
> simple that solves the emerging Ajax web application web
> browser history problem, something that is strongly tight
> to the xmlhttp request object and would be easy to
> implement by user agent vendors.

Karl, I strongly believe that modifying browser's engines to save *state* in addition to URL just cannot be simple enough. I highly doubt it would be implemented any soon.

As says here, "Part of the AJAX problem is understanding whether an AJAX enhanced page is actually a web application, or is it still just a web document?"

I believe that an AJAX enhanced page should be considered a web application by itself. I also believe, that the best and really easy solution would be to conditionally disable "Back" and "Forward" buttons on an AJAX page. When I said "conditionally" I meant that in case a user clicks one of these buttons a browser should display a confirmation window asking if user really wants to *leave application*.

Yes, it would break a "pure HTML ideology", but this ideology applies to web pages, not to web applications.

AJAX web pages aren't first pages which would benefit from conditionally disabling "Back" and "Forward" buttons. The same issue arises for any web pages with dynamically modified content: for pages with frames, for pages with Java applets or ActiveX controls.

Even plain HTML pages generated by server-side (PHP, ASP, etc.) script often experience troubles with "Back" and "Forward" buttons. Consider a standard situation when a page uses HTML form to POST to itself, or when server-side script uses SESSIONS to save data on a server side. It immediately breaks a normal behavior of "Back" and "Forward" buttons, because document's *state* is not exclusively determined by a URL, it may depend on a session variable or even data, retrieved from a database.

So, again, such pages are web applications by themselves - something similar to a graphical Windows desktop application, and they should be able to restrict "Back" and "Forward" buttons' behavior.

Internet Explorer does provide a way to do it with onbeforeunload Event.
Unfortunately, other browser's vendors consider themselves more "purist" and do not provide such ability. If you try to Google like this you'll get a long list of messages from people struggling to disable those buttons... I understand that controlling "Back" and "Forward" buttons' behavior from a loaded HTML document may introduce some security risks, but I think that it well worth to implement as standard behavior - advantages are immense.

***************
In reply to Garret Wilson's message I said that:

Garret Wilson wrote:
> Web applications are truly applications, and it may be
> correct for them to expose certain commands to their
> runtime container (which may be a browser)

I think that you words apply perfectly to "Back" and "Forward" browser's buttons which should be controllable to certain degree by HTML document itself. If properly implemented, it would solve a lot of problems with dynamic web pages (like pages using AJAX) being not compatible with "Back" and "Forward" buttons - because they lose their state when browser leaves a page.

See Ajax Back/Forward History problem thread here and/or here.
Also take a look at Ajax Mistakes topic SourceLabs forum.

***************
After thinking about this issue and reading more articles I understood, that we should distinguish two different situations of using "Back" and "Forward" buttons:
1) To Enter/Exit current web application.
2) To travel inside current web application.

All my words above about conditional disabling of buttons apply to 1).
In 2) "Back" and "Forward" buttons are a convenient tool. I recently found an article written by Mike Stenhouse and called Fixing the Back Button and Enabling Bookmarking for AJAX Apps. It does allow to use navigation buttons inside AJAX application. But despite the fact that it's a clever code, I consider it as a hack. Just too much smart efforts for such a simple and common thing.
I wonder why it is considered better to have navigational buttons provided by a container (web browser). Coming from a windows desktop applications background (VB/Delphi) I would say, that it is oftensimplerr and more flexible to control navigation inside an application using its own tools. Speaking about web application, I would say that it is often better todisablee "Back" and "Forward" buttons inside application and to use application's custom buttons/links to go back and forth.
Unless some major changes are incorporated into modern browsers allowing to track changing state by means of AJAX.

A good website and ACRONYM and ABBR tags

I was browsing developer's sites all the day and found a site which is IMHO good for all Web developers
http://www.w3schools.com/default.asp
There are tutorials on almost all Web-related technologies!

In particular, I was surprised to find simple HTML tags I've never heart about:
ABBR and ACRONYM
http://www.w3schools.com/tags/tag_abbr.asp
http://www.w3schools.com/tags/tag_acronym.asp

Move a mouse over dotted words on this page to see how it works.

Open IE in Mozilla/Firefox Tab

If, for some crazy reason you just want to open some page not in your normal Firefox/Mozilla, but in IE...

Google rules!

I wanted to install Google Toolbar on my home machine to be able to spell check on any form - just as I did recently at work, started to look at Google pages and immediately got lost with it's endless features. I went to Google Blog Search, searched for "AJAX" and found... Guys, for example, take a look at AJAX-based slideshow here!