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

Two ways of opening a new window

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.