By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,561 Members | 3,113 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,561 IT Pros & Developers. It's quick & easy.

Mozilla onload: "no properties"; IE OK

P: n/a
kj


This problem is driving me nuts. The code at the end of this post
below works fine with IE, but fails with Mozilla. You can see it
in action at

http://tinyurl.com/2jvo3

With Mozilla 1.4 and 1.6, the function msg works fine if it's
installed as an onclick handler for the button, but fails as an
onload handler for the page. The error is "console has no properties",
and is triggered by the line.

console.document.open("text/plain");

The code works fine on all versions of IE I've tested it on.

Is there an error in my code (that IE is letting slide), or is this
a bug in Mozilla? If the latter, is there a workaround?

Thanks!

kj

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN"
"http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">

<head><title>JAVASCRIPT STUMPER</title></head>
<body onload="javascript:msg('PLEASE HELP ME!!!') // bombs on NS, moz">

<script type="text/javascript">

// Adapted from Flanagan's "javascript: The Definitive Guide", 3rd Ed.

var console = null;
var litany = "";
var times = 0;

function msg(s) {
var MHUAHAHA = "";
if ((console == null) || (console.closed)) {
console = window.open("","console","width=600,height=300,res izable");
console.document.open("text/plain");
MHUAHAHA = litany;
}

MHUAHAHA += (++times > 1
? "I've told you " + times + " times already!!! "
: "") + "RESISTANCE IS FUTILE!\n";

console.document.write(MHUAHAHA);
litany = MHUAHAHA;
}

</script>
<h1>ALL YOUR BASE ARE BELONG TO US!</h1>
<form>
<input type=button value="HELP!!!" onclick="javascript:msg(this.value)"/>
</form>
</body>
</html>
--
NOTE: In my address everything before the period is backwards.
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
kj wrote:
This problem is driving me nuts. The code at the end of this post
below works fine with IE, but fails with Mozilla. You can see it
in action at

http://tinyurl.com/2jvo3

With Mozilla 1.4 and 1.6, the function msg works fine if it's
installed as an onclick handler for the button, but fails as an
onload handler for the page. The error is "console has no properties",
and is triggered by the line.

console.document.open("text/plain");

The code works fine on all versions of IE I've tested it on.

Is there an error in my code (that IE is letting slide), or is this
a bug in Mozilla? If the latter, is there a workaround?

Thanks!

kj

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN"
"http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">

<head><title>JAVASCRIPT STUMPER</title></head>

<body onload="javascript:msg('PLEASE HELP ME!!!') // bombs on NS, moz">

<script type="text/javascript">

// Adapted from Flanagan's "javascript: The Definitive Guide", 3rd Ed.

var console = null;
var litany = "";
var times = 0;

function msg(s) {
var MHUAHAHA = "";
if ((console == null) || (console.closed)) {
console = window.open("","console","width=600,height=300,res izable");
This is an asynchronous method call. window.open() is called, opens a new
window and returns a reference to the newly created window. There is no
guarantee, none, that when the method window.open() returns, there is a valid
document in the newly created window.
console.document.open("text/plain");
You immediately attempt to access the document property of the newly opened
window, as stated above, there is no guarantee that a document property of a
newly opened window is available to do _anything_ with immediately following
a window.open() call.
MHUAHAHA = litany;
}

MHUAHAHA += (++times > 1
? "I've told you " + times + " times already!!! "
: "") + "RESISTANCE IS FUTILE!\n";

console.document.write(MHUAHAHA);
litany = MHUAHAHA;
}

</script>
<h1>ALL YOUR BASE ARE BELONG TO US!</h1>
<form>
<input type=button value="HELP!!!" onclick="javascript:msg(this.value)"/>
</form>
</body>
</html>


The "fix" or "workaround" is to actually load a .html file into the newly
created window that contains something like:

<body onload="if (opener && opener.callBack) opener.callBack();">

callBack(); would be a function in the opener window that writes whatever
content you want to the newly created window (or does whatever else you would
like done). In this way, you can be assured that the only time the code to
write content to the new window runs is once the new window is opened and
ready for it's content.

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 23 '05 #2

P: n/a
Lee
kj said:



This problem is driving me nuts. The code at the end of this post
below works fine with IE, but fails with Mozilla. You can see it
in action at

http://tinyurl.com/2jvo3

With Mozilla 1.4 and 1.6, the function msg works fine if it's
installed as an onclick handler for the button, but fails as an
onload handler for the page. The error is "console has no properties",
and is triggered by the line.


Mozilla is blocking popups. A window.open() call from
the onload handler is considered to be a popup that
should be blocked. You can change that setting.

Jul 23 '05 #3

P: n/a
DU
Grant Wagner wrote:
kj wrote:

This problem is driving me nuts. The code at the end of this post
below works fine with IE, but fails with Mozilla. You can see it
in action at

http://tinyurl.com/2jvo3

With Mozilla 1.4 and 1.6, the function msg works fine if it's
installed as an onclick handler for the button, but fails as an
onload handler for the page. The error is "console has no properties",
and is triggered by the line.

console.document.open("text/plain");

The code works fine on all versions of IE I've tested it on.

Is there an error in my code (that IE is letting slide), or is this
a bug in Mozilla? If the latter, is there a workaround?

Thanks!

kj

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN"
"http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">

<head><title>JAVASCRIPT STUMPER</title></head>

<body onload="javascript:msg('PLEASE HELP ME!!!') // bombs on NS, moz">

<script type="text/javascript">

// Adapted from Flanagan's "javascript: The Definitive Guide", 3rd Ed.

var console = null;
var litany = "";
var times = 0;

function msg(s) {
var MHUAHAHA = "";
if ((console == null) || (console.closed)) {
console = window.open("","console","width=600,height=300,res izable");

This is an asynchronous method call. window.open() is called, opens a new
window and returns a reference to the newly created window. There is no
guarantee, none, that when the method window.open() returns, there is a valid
document in the newly created window.

console.document.open("text/plain");

You immediately attempt to access the document property of the newly opened
window, as stated above, there is no guarantee that a document property of a
newly opened window is available to do _anything_ with immediately following
a window.open() call.


Correct. He also calls, uses a parameter which is no longer valid in DOM
2 HTML. open() takes no parameters.

http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-72161170

MHUAHAHA = litany;
}

MHUAHAHA += (++times > 1
? "I've told you " + times + " times already!!! "
: "") + "RESISTANCE IS FUTILE!\n";

console.document.write(MHUAHAHA);
litany = MHUAHAHA;
He never closes the document stream: so the browser waits (Mozilla-based
browsers are more sensitive to this) for more info and keep the stream
open. It gives the user the impression that the document never ends
loading, the progress icon never stops turning, progressmeter is always
active, as if the browser is always waiting for more info.

"close
Closes a document stream opened by open() and forces rendering."

http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-98948567
}

</script>
<h1>ALL YOUR BASE ARE BELONG TO US!</h1>
<form>
<input type=button value="HELP!!!" onclick="javascript:msg(this.value)"/>
</form>
</body>
</html>

The "fix" or "workaround" is to actually load a .html file into the newly
created window that contains something like:

<body onload="if (opener && opener.callBack) opener.callBack();">

callBack(); would be a function in the opener window that writes whatever
content you want to the newly created window (or does whatever else you would
like done). In this way, you can be assured that the only time the code to
write content to the new window runs is once the new window is opened and
ready for it's content.


I entirely agree with your explanations and solution. I think this
problem is so often encountered and is not well documented that it
should be addressed by this newsgroup FAQ.
This happened to me once and I couldn't find any documentation on this
issue.

DU
--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html

Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.