Click to See Complete Forum and Search --> : pop-up new window using document.write


zwirley
03-11-2003, 02:17 AM
I'm dynamically creating the contents of my html page, the page includes a link that would pop up a new window without the toolbar and stuffs. I've tried everything to call the pop up window but it kept showing me "Object Expected" error. Any help would be appreciated. Thanks

<script language="javascript">
function testLink()
{
document.open();
document.write('<body bgcolor="#FFFFFF">');
document.write('<table width="100%" border="0" align="center">');
document.write('<tr><td>');
document.write('<a href="javascript:NewWindow(\'deviationFrame.html\', \'deviationFrame\')">');
document.write('POPUP WINDOW</a></td></tr></table></body>');
document.close();
}

function NewWindow(myPage, myName)
{
w = 950
h = 620

var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+no+',resizable'
win = window.open(myPage, myName, winprops)
}
</script>

<body bgcolor="#FFFFFF" text="#000000" onLoad="testLink()">
<form name="form1" method="post" action="">
</form>
</body>
</html>

khalidali63
03-11-2003, 03:08 AM
If you want to do it the way its posted,then you will have to put this function
NewWindow()

in a openwin.js file and import this file.
Assuming you have done the above

this code will open the popup


<script type="text/javascript">
function testLink(){
document.open();
document.write('<body bgcolor="#FFFFFF">');
document.write('<script type="text/javascript" src="openwin.js"><\/script>');
document.write('<table width="100%" border="0" align="center">');
document.write('<tr><td>');
document.write('<a href="javascript:NewWindow(\'deviationFrame.html\', \'deviationFrame\')">');
document.write('POPUP WINDOW</a></td></tr></table></body>');
document.close();
}
</script>

<body bgcolor="#FFFFFF" text="#000000" onLoad="testLink()">


The reason it would not work was when you use document.write once this statement is finished executing everything else is out of scope.

Cheers

Khalid

dhermes
03-11-2003, 08:04 PM
<a href="#" onClick="window.open('page to popup','window','scrollbars=yes,toolbar=no,directories=no,width=752,height=550')">

This is a very simple version of a popup window, of course enter the pup up windows name in place of 'page to pop up' and at the end of the scrip is where you text goes.

I don't know if this is helpful in your situation or not.

zwirley
03-12-2003, 01:58 AM
guys, thanks for all the help :)
I placed my function into the document.write and got it running.