aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Title sometimes wrong until JavaScript finishes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Title sometimes wrong until JavaScript finishes" Watch "Title sometimes wrong until JavaScript finishes" New topic
Author

Title sometimes wrong until JavaScript finishes

Louise Brown
Greenhorn

Joined: Sep 08, 2008
Posts: 4
Sometimes when I display a web page, the title that appears at the top of the browser window is incorrect, but then it automatically changes to the correct title. It seems that the browser does this:
1) Display the title at the top of the browser window as the html file name (in Safari), or the title of the previous web page (in Firefox).
2) Execute any window.onload JavaScripts.
3) Change the title at the top of the browser window to the correct title.

For example, suppose you display this file in Safari on a Mac. The title at the top of the browser window will be the name of the html file for a moment, before the correct title appears.

The delay in displaying the correct title also occurs if the user has to respond to an alert. For example in this web page, you see the file name as the title, until you respond to the alert (using Safari on a Mac):

With Safari, I have this problem with both of the above html files. With Firefox, I have this problem only with the first file (the web page that increments i). With Opera, both html files work ok.

Setting the title at the top of the JavaScript doesn't solve the problem - the correct title doesn't appear until after the JavaScript finishes.

If I refresh the web page, the title is ok - the correct title appears right away. I have this problem only when I display the web page in a new window.

I tried putting the JavaScripts into jQuery $(document).ready functions, but had the same problem.

Does anyone have a suggestion for how to make the correct title (either in the <title> tag, or set by "document.title =") appear immediately? Thank you very much.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Nothing magical here. If something locks up the browser, it will not update immediately.

Eric
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Title sometimes wrong until JavaScript finishes