opening a new window with HTML code instead of file

L

laredotornado

Hello,
I am searching for a cross-browser way (the most recent browsers
are fine) to use javascript to open a new window even though I do not
know the file I want to call. I do, however, know the HTML code I want
output in the new window. It would look like

<HTML>
<HEAD><TITLE>Hello</TITLE>
</HEAD>
<BODY>
Hello
</BODY>
</HTML>

I understand I could put this text into a file and call that, but if
there were a way to automatically populate the window with this code,
prior to opening it, that would be the ideal.

Thanks, - Dave
 
C

Csaba Gabor

Hello,
I am searching for a cross-browser way (the most recent browsers
are fine) to use javascript to open a new window even though I do not
know the file I want to call. I do, however, know the HTML code I want
output in the new window. It would look like

var newWin = window.open("about:blank");
newWin.document.open();
newWin.document.write("<body>Some text</body>");
newWin.document.close();
newWin.document.title = "My favorite title";

See also perhaps the recent discussion at:
http://groups.google.co.uk/group/comp.lang.javascript/browse_frm/thread/18a60664279d6460/

Csaba Gabor from Vienna
 
L

laredotornado

Thanks but sadly when I try this code on PC IE 6.0, I get a javascript
error that says "Access Denied".

Is there another way?

- Dave
 
A

askMe

You would have to change the "about:blank" to a "/" or something to get
the address bar to look right.

function javascripttest()
{
var newWin = window.open("/");
newWin.document.open();
newWin.document.write("<body>My virtual web page <BR> is what you
see!</body>");
newWin.document.title = "My virtual title";
newWin.document.close();
return;
}

http://www.askblax.com
 
C

Csaba Gabor

Thanks but sadly when I try this code on PC IE 6.0, I get a javascript
error that says "Access Denied".

The popup blocker's stance is that it will only put up a popup on a
user initiated action. That means things like clicking on buttons,
etc. Unfortunately, IE/FF will not respond to popup attempts as a
result of a keyboard listener (document.onkeyup = function() {...} )
even though it's pretty clear that pressing a ctrl+key is not an
accidental user action.

The code below now includes a button you may press.
Csaba Gabor


<button onclick="dome()" accesskey=d><u>D</u>o me
<script type='text/javascript'>
function dome() {
var newWin = window.open("about:blank");
newWin.document.open();
newWin.document.write("<body>Some text</body>");
newWin.document.close();
newWin.document.title = "My favorite title";
}
</script>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top