...

View Full Version : Popup script that isn't actually another HTML file



Erica_qt
04-01-2003, 05:10 AM
Hi, I'm pretty certain I've seen this done before, but I don't know if it was just HTML, or JavaScript, or what (but I assume it was a javascript, so I'm putting it in here)... Is it possible to make a link on the HTML page, so that when you click it, a popup comes up with text and scripts and everything in it... except that all the text and scripting in that popup is ACTUALLY in the original HTML file.

HairyTeeth
04-01-2003, 09:01 AM
A simple demo...
(EDIT: fixed typos and included document.close())


<html>
<head>
<title>Demo</title>
<script language="jav&#97;script" type="text/jav&#97;script">
<!--

var myPopup
function openPopup(){

myPopup=window.open('','myPop','width=400,height=400')
myPopup.document.write("<html><head><title>Popup</title>")
myPopup.document.write("<body><h1>Hello</h1></body>")
myPopup.document.write("</html>")
myPopup.document.close()
}
//-->
</script>
</head>
<body>
<a href="jav&#97;script: openPopup()">Open popup window</a>
</body>
</html>

It can get a bit trickier than this but it will give you the idea.

Erica_qt
04-01-2003, 01:50 PM
That script didn't work. It's probably one of those things where it's just a typo spelling error somewhere. I took out the extra "a" in "javaascript", but that still didn't fix it, or there's another typo somewhere.

:EDIT:
I found the other error, down near the bottom it said "java script". I took out the space, and it now works.

Thanks a ton for the script!!!

beetle
04-01-2003, 02:41 PM
Missing one crucial step

myPopup=window.open('','myPop','width=400,height=400')
myPopup.document.write("<html><head><title>Popup</title>")
myPopup.document.write("<body><h1>Hello</h1></body>")
myPopup.document.write("</html>")
myPopup.document.close();

That closes the output stream to the new window and allows it to render ;)

liorean
04-01-2003, 03:13 PM
Beetle - actually, it renders without document.close. document.close only tells the browser to close the input stream, by what it knows that there will be no more content for it to render, and thus the load even can be triggered.

cheesebagpipe
04-02-2003, 02:00 AM
Alternative:

<html>
<head>
<title>Demo</title>
<script language="javascript" type="text/javascript">
<!--

var myPopup = null;
var HTML;
function openPopup(){
HTML = '';
HTML += "<html><head><title>Popup</title>";
HTML += "<body onload=setTimeout('self.close()',2000)><h1>Hello</h1></body>";
HTML += "</html>";
myPopup=window.open('javascript&#58;opener.HTML','myPop','width=400,height=400');
}

//-->
</script>
</head>
<body>
<a href="javascript&#58;void openPopup()">Open popup window</a>
</body>
</html>

I've found this to be much more reliable, since the new document is written to synchronously (by .open()), avoiding the 'access denied' errors that plague IE when you do it on-the-fly.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum