Lee wrote:
Jenny said:
In the code below, I can write html content var t='<body
BGCOLOR=blue>'
for a new window. But if it contains javascript, such as var
t='<body onload="window.open('new1.html')">', this code will not work.
The problem isn't that the string contains Javascript, but that the
syntax is wrong. You cannot nest quotes like that.
The correct syntax is:
t='<body onload="window.open(\'new1.html\')">'
And it still won't work on many, many browsers, among them:
- IE < 6.0.2900 running the Google toolbar (in it's default configuration)
or another popup blocker
- IE 6.0.2900 (XP SP2) in it's default configuration
- Any Gecko-based browser in it's default configuration
- Opera 7.54 if configured to "Block unwanted (or all) pop-ups"
None of these browsers in the configurations shown allow a body onload
event to open a new window.
If this is an Intranet where you control the browsers being used, and their
configuration, then by all means open the new window in the onload event of
the body.
If this is a public Internet site, please abandon this design now.
And lastly, I believe document.write()ing a <body> tag into an HTML
document results in an invalid document:
<body>
<script type="text/javascript">
document.write('<body onload="window.open(...);">');
</script>
<!-- ... -->
</body>
- results in the document having two <body> tags, which is invalid HTML.
</head>
<script type="text/javascript">
document.write('<body onload="window.open(...);">');
</script>
<!-- ... -->
</body>
- results in the document having <script> tags outside of either
<head></head> or <body></body>, which is invalid HTML. You also run the
risk that JavaScript will be unavailable on the client and you'll end up
with no <body> tag at all, which would be invalid HTML.
If you want to set the onload event programmatically use:
<head>
<script type="text/javascript">
window.onload = function() {
window.open(...);
}
</script>
</head>
<body>
--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ -
http://jibbering.com/faq