469,575 Members | 1,479 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,575 developers. It's quick & easy.

Two ways of opening a new window

What's the difference between the two ways of opening a new window and
writing to it?

Let's say I prepare a code that goes into a new window and save it in a
variable winHTML:

var winHTML = "<HTML><HEAD><TITLE>Any title</TITLE><BODY>Any
text</BODY></HEAD>";

Now, I have two ways to open a new window and write that code into the new
window:

One way is:
var newWin=window.open();
newWin.document.open();
newWin.document.write(winHTML);
newWin.document.close();
newWin.focus();

Other way is:
window.open("javascript:opener.winHTML");

Is there any reason why to prefer one over the other?
Jul 23 '05 #1
4 2316
On Wed, 26 May 2004 17:04:03 GMT, Amir wrote:
var winHTML = "<HTML><HEAD><TITLE>Any title</TITLE><BODY>Any
text</BODY></HEAD>";


...perhaps you should validate that as HTML first.

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Jul 23 '05 #2
Andrew Thompson wrote:
var winHTML = "<HTML><HEAD><TITLE>Any title</TITLE><BODY>Any
text</BODY></HEAD>";


..perhaps you should validate that as HTML first.

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology


var winHTML = "<HTML><HEAD><TITLE>Any title</TITLE><BODY>Any
text</BODY></HTML>";

However, the JavaScript question was as clear as it is now. I wouldn't
attach too much importance to minor HTML errors, unless I present a question
that requires running a code.
Jul 23 '05 #3
Lee
Amir said:

What's the difference between the two ways of opening a new window and
writing to it?

Let's say I prepare a code that goes into a new window and save it in a
variable winHTML:

var winHTML = "<HTML><HEAD><TITLE>Any title</TITLE><BODY>Any
text</BODY></HEAD>";

Now, I have two ways to open a new window and write that code into the new
window:

One way is:
var newWin=window.open();
newWin.document.open();
newWin.document.write(winHTML);
newWin.document.close();
newWin.focus();

Other way is:
window.open("javascript:opener.winHTML");

Is there any reason why to prefer one over the other?


I routinely use the second. The window.open() method returns
without guaranteeing that the window has been created yet, so
there have been many posts to this newsgroup asking why that
method fails some of the time.

I've never had any trouble with the second form.
That sort of thing is exactly what the "javascript:"
pseudo-protocol was created for.

note that you can send focus to the window (as you do in your
first example), with:

window.open("javascript:opener.winHTML").focus();

Jul 23 '05 #4
Amir wrote:
Andrew Thompson wrote:
var winHTML = "<HTML><HEAD><TITLE>Any title</TITLE><BODY>Any
text</BODY></HEAD>";
..perhaps you should validate that as HTML first.

[...]

var winHTML = "<HTML><HEAD><TITLE>Any title</TITLE><BODY>Any
text</BODY></HTML>";


Nothing has changed, this is still invalid HTML. Besides, the ETAGO
delimiters (</) can cause trouble as it marks the end of the element in
SGML. If you use that sequence in scripts embedded in HTML documents,
escape it. In J(ava)Script you would do that with "<\/".
However, the JavaScript question was as clear as it is now. I wouldn't
attach too much importance to minor HTML errors, unless I present a
question that requires running a code.


You can't build a house on a swamp.

And please, trim your quotes and use a "From" header
that complies with Internet/Usenet standards.
PointedEars
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Dena Leiter | last post: by
14 posts views Thread by D. Alvarado | last post: by
reply views Thread by bbrewder | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.