473,385 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

write content for new window

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.
Could you confirm this and find such syntax rule for me on the
internet? Thank a lot.

<html><head>
</head><body>
<SCRIPT language=JavaScript>
w=open("new.html")
//var t='<body onload="window.open('new1.html')">'
var t='<body BGCOLOR=blue>'
w.document.write(t);
</SCRIPT ></body>
</html>
Jul 23 '05 #1
2 4560
Lee
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\')">'

Jul 23 '05 #2
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

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: James Marshall | last post by:
I'm writing a library where I want to override document.write(), but for all document objects; thus, I want to put it in the prototype. I tried Document.prototype.write= my_doc_write ; but it...
2
by: Brett Baisley | last post by:
Hello I have a block of html code that I want to run by calling a javascript function to print it. Its basically a table with menu items in it that is the same for many pages, and instead of...
1
by: Vincy | last post by:
Hi, I have the follow problem: a windows is divided on two frames: frame1 and frame2. on frame 2 there is a buttom it runs a function 'SendMsg' that write (by operator 'write' of javascript) a...
2
by: Adam | last post by:
This is frustrating me. Opening IE displays the following code fine. When I open a new window the code no longer works. All the HTML is overwritten with the first document.write statement. Tried...
11
by: Russ | last post by:
My web app writes some binary data to a file at the client site via Response.Write and Response.BinaryWrite. This action is accomplished in response to a button click, with C# code behind as...
8
by: '69 Camaro | last post by:
Perhaps I'm Googling for the wrong terms. Does anyone have links to examples of the syntax necessary to read the HTML on another Web page when that HTML is produced from JavaScript using the...
1
by: Angelos | last post by:
Hello there, I am very new to Javascript and before I explain what I want I'll tell you in a few words that I am trying to make a button on a WYSIWYG text editor (RichArea) that previews on a...
4
by: ArrK | last post by:
I want to use a control frame to create and/or modify the content (images and text) of a display frame - all files and images are client side. . When I try to write to the display frame from the...
27
by: Inny | last post by:
The following 3 pages which are popups on my site are not rendering in mozilla firefox. Source is visible instead. Any idea why? ...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.