DOM problem with V7 and later
DOM function such as document.open() and document.getElementById() cease to work in my website from V7 onwards
All Replies (8)
Fails @line: nuDocument.writeln("<html>");
What is the error message that you get in Firefox's Error Console (Ctrl+Shift+j to open)?
Can you post a link to a page exhibiting this problem?
Modified
Hi,
Error message is:
Timestamp: 13/04/2012 17:25:06 Error: nuDocument is null Source File: http://www.brianleigh.net/ExcavationModel/createObjectZM.js Line: 540
You can get to the page via www.brianleigh.net/ExcavationModel & clicking on 'documents'.
Many thanks for your support.
Did you ever get the reply I posted? It seems to have disappeared from the record. In case you didn't, here it is again: www.brianleigh.net/ExcavationModel and click on 'Documents'. It would be nice to have a resolution to this sometime soon. Many thanks, Brian Leigh
A good place to ask advice about web development is at the MozillaZine "Web Development/Standards Evangelism" forum.
The helpers at that forum are more knowledgeable about web development issues.
You need to register at the MozillaZine forum site in order to post at that forum.
I got a blank page with your link. Are you sure your page is well coded?
I looked at the page, but since document.open() worked for me in a simplified example, I don't really have any idea why it isn't working in your page.
Simplified example: http://jeffersonscher.com/forumshots/document_open.html
Firefox seems to behave very strange with using document.open in a script.
The change seems to be from Firefox 6 to Firefox 7.
Some code to play with:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html><head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>document.open test</title> <script type="text/javascript"> function newDocument(i,j){ var nuDocument = document.open(); if(j)alert(nuDocument+"\n"+i); if(nuDocument){ nuDocument.writeln("<html>"); nuDocument.writeln("<body><p>Replaced by JavaScript ("+i+")</p></body>"); nuDocument.writeln("</html>"); nuDocument.close(); } return; } newDocument(0,1); setTimeout(function(){newDocument(1,0);},0); //setTimeout(function(){newDocument(2,1);},500); </script> </head><body> <h1>document.open test</h1> <p><button onclick="newDocument(3,1);">Replace document</button></p> </body></html>
Modified
Hi Cor-el. Yes, very peculiar behaviour indeed - as your code suggests, there seems to be some sort of timing problem when invoking the function. The really strange thing is that it works perfectly with a zero timeout but not with a 500ms one. I'll apply this to my own code & hope it solves the problem. Does this sort of thing ever get flagged up to the Firefox developers, as it seems like a straight bug to me & as it's been around from V7 it should surely have been fixed by now? Many thanks.