im trying to open a Javascript window and write content into it without having to load another page.
this is my script so far,
HTML Code:
<head><title>popups javascript</title><script type=text/javascript>
function popitup2() {
newwindow2=window.open('','name','height=200,width=150');
var tmp = newwindow2.document;
tmp.write('<html><head><title>popup</title>');
tmp.write('<script type=text/javascript>');
tmp.write('var d=new Date(); document.write(d.getHours()+":"+d.getMinutes());');
tmp.write('</script></head><body><p>this is once again a popup.</p>');
tmp.write('</body></html>');
tmp.close();
}
</script></head><body><form><input type="button" onClick="popitup2()" value="POP!"></form><p onClick="popitup2()">CLICK ME TOO!</p></body>
i dont know what is wrong?
and
iam wondering if this is the better way to do it[prev. content: only few lines]. it's also possible to do it in easier way, please share
popups take a while to "boot", during which the DOM has not been built.
maybe something like this?
Code:
function popitup2() {
newwindow2=window.open('','name','height=200,width=150');
newwindow2.onload=function(){
var tmp = newwindow2.document;
tmp.write('<html><head><title>popup</title>');
tmp.write('<script type=text/javascript>');
tmp.write('var d=new Date(); document.write(d.getHours()+":"+d.getMinutes());');
tmp.write('</script></head><body><p>this is once again a popup.</p>');
tmp.write('</body></html>');
tmp.close();
}
}
tmp.write('</script></head><body><p>this is once again a popup.</p>');
I think most browsers won't allow unescaped </script> tags even in JS strings.
Try escaping the slash, i.e.
Code:
tmp.write('<\/script></head><body><p>this is once again a popup.</p>');
yes. its working
but , Popup don't present content only a blank screen...
so, i try this
HTML Code:
<script type=text/javascript>
function popitup2() {
var tmp='<html><head><title>popup</title>';
tmp+='<script type=text/javascript>';
tmp+='var d=new Date(); document.write(d.getHours()+":"+d.getMinutes());';
tmp+='<\/script></head><body><p>this is once again a popup.</p>';
tmp+='</body></html>';
var newwindow2=window.open('','name','height=200,width=150');
newwindow2.document.write(tmp);
}
</script></head><body><form><input type="button" onClick="popitup2()" value="POP!"></form><p onClick="popitup2()">CLICK ME TOO!</p></body>
Bookmarks