Welcome to WebmasterWorld Guest from 23.22.79.235

Forum Moderators: incrediBILL

Message Too Old, No Replies

Firefox trouble - it never finishes loading

   
2:03 pm on Jan 17, 2005 (gmt 0)

10+ Year Member



Hi all

Up till recently I was developing a site in IE. Now i've switched to Firefox, and have encountered some strange faults. One of them is a popupwindow where I use javascript to populate it. IE have no problems displaying the window and it's contents. FF displays the window, but in the statusbar it says "transferring data..." forever as if all of the page couldn't be read from the server...
This is somewhat anoying as I wish to probe the html-source with FF's view page source, and this is impossible until the page is fully loaded.

regards tores

3:22 pm on Jan 17, 2005 (gmt 0)

10+ Year Member



Have done some testing around this and narrowed it down to the following code:

<script language="Javascript">
win=window.open("","id","status=yes,width=300,height=300");
win.document.write('<html>Hello</html>');
</script>

Firefox prints "hello" but stops loading the page after that, when the "load-bar" on the statusline is only about 33% filled...

regards tores

3:49 pm on Jan 17, 2005 (gmt 0)

WebmasterWorld Senior Member blobfisk is a WebmasterWorld Top Contributor of All Time 10+ Year Member



How about using innerHTML instead?
4:19 pm on Jan 17, 2005 (gmt 0)

10+ Year Member



How do I use InnerHTML? Can u show me an example?
4:35 pm on Jan 17, 2005 (gmt 0)

WebmasterWorld Senior Member blobfisk is a WebmasterWorld Top Contributor of All Time 10+ Year Member



You will need to create your popup and write the main elements out (html, body etc.), but useage would be:

document.getElementById('bodyID').innerHTML = '<p>Hello World</p>';

HTH

4:49 pm on Jan 17, 2005 (gmt 0)

10+ Year Member



Tried innerHTML but that gave the same result...
Maybe it's a just a bug in FF...
5:11 pm on Jan 17, 2005 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



This is most likely your problem:

<script language="Javascript">
win=window.open("","id","status=yes,width=300,height=300");
win.document.write('<html>Hello</html>');
win.document.close();
</script>

When you write to a document closing the document flushes the buffer and prints to the document, it's a very common mistake for new coders. If you load an actual PAGE in the URL parameter, you don't need to close it.

While we're on it this is something you probably want to add:

<script language="Javascript">
var day = new Date();
var id = day.getTime();

win=window.open("",id,"status=yes,width=300,height=300");
win.document.write('<html>Hello</html>');
win.document.close();
</script>

Note the removed quotes around id because it is now a variable. With your previous code, every "new window" called by this method would open in the SAME window. Assigning a relatively unique ID to the window forces a NEW one to open each time.

The reason this is important is if you're calling the same sub from various pages and the user leaves the initial pop-up open, the'll click new pop-ups and it will appear that "nothing happens" even though it's loading in the initial new window, which is now behind the current window . . . .

5:25 pm on Jan 17, 2005 (gmt 0)

10+ Year Member



document.close()... That was it:)

Thanks a lot. IE is nice in the way that it forgives and corrects many of your mistakes, but with FF one actually is forced to produce correct code, and in doing so learning new stuff:)

7:15 am on Jan 18, 2005 (gmt 0)

10+ Year Member



There's a third alternative that wasn't mentioned above, the DOM appendChild() function and its relatives. Unlike innerHTML, they have the advantages of being fast and standard-compliant. innerHTML is an obsolete IE property that's been picked up by a few other browsers.

The main drawback is that createElement(), appendChild(), etc. are a little more complex to use.