Closed Bug 259209 Opened 20 years ago Closed 20 years ago

JavaScript global variables destroyed on document.write

Categories

(Core :: DOM: Core & HTML, defect)

x86
Windows XP
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 114461

People

(Reporter: jbwalker, Unassigned)

Details

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.2) Gecko/20040803
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.2) Gecko/20040803

Problem found in Firefox 0.93 and Mozilla 1.7. I have looked through existing bugs.

JavaScript file below. showVars() is called by BODY onLoad event. Generic,
minimal html page so haven't bothered to submit. Works in IE. Tracked in Venkman
and found that Global variables (browser, vers, uA, etc) worked fine until first
document.write executed, when they all disappeared. Can't see that this is an
expected result (ie I have a screwed up understanding of js) but will keep
checking. Many, many apologies if I am mistaken and no need to reply/explain. 

// ASSESS WINDOW STATUS
	var winW; 
	var winH;
	var browser = navigator.appName;
	var uA = navigator.userAgent;
	var vers;

function showVars() {
   if (browser=="Netscape") {
		try {
   		vers = parseInt(window.navigator.appVersion);
			alert(vers)
			winW = window.innerWidth;
			winH = window.innerHeight;
	   	}
		catch (er) {alert(er);}
	   }
	else
	   {
		if (browser.indexOf("Microsoft")!=-1) {
		   vers = parseInt(navigator.appVersion)
	       winW = document.body.offsetWidth;
	       winH = document.body.offsetHeight;
	       }
	   }
	alert(uA);
	if (browser) document.write("Browser:'"+browser+"'<BR>");
	// document.write("Vers:'" + vers + "'<br>");
	document.write("User agent:" + uA);
	document.write("Window width:" + winW);
	document.write("       height:" + winH);
	}

Reproducible: Always
Steps to Reproduce:
1. Create anyold html page. Attach js script above to BODY onload event.
2. load page


Actual Results:  
3. script crashes (no output after "Browser:...")

Expected Results:  
Should show page with contents of uA, etc. (IE does and it does suck!)

I'd add more details but I've suspected similar problems in previous builds of
both Mozilla and Firefox
This bug is a duplicate.

/be
Whiteboard: DUPEME
And it's not a JavaScript Engine bug -- reporter take note.

/be
Status: UNCONFIRMED → NEW
Component: JavaScript Engine → DOM: Level 0
Ever confirmed: true

*** This bug has been marked as a duplicate of 114461 ***
Status: NEW → RESOLVED
Closed: 20 years ago
Resolution: --- → DUPLICATE
Whiteboard: DUPEME
You need to log in before you can comment on or make changes to this bug.