Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

close parent window

Status
Not open for further replies.

Bakunin

Programmer
Dec 21, 2000
31
GB
Hi,
I have been trying to implement an ( apparently ) simple operation. I want to open a window from an existing parent window with a button, when the button is pressed the parent closes. I had tried to use the opener keyword, but when I tried to embed javascript in the new window, I got "unterminated string errors", or "object errors". Does anyone have some simple source to achieve this.

<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<HTML>

<HEAD><TITLE>New Window Test</TITLE>
<FORM>

<BODY>
<SCRIPT language=JavaScript>
<!--
function newWin()
{


pageContent = &quot;<HTML><HEAD><TITLE>&quot;;
pageContent += &quot;Close Parent Test</TITLE>&quot;;

pageContent += &quot;</HEAD><FORM><BODY>&quot;;


pageContent += &quot;<script langauge='JavaScript'><!-- opener.close(); //--></script>&quot;;


pageContent += &quot;</BODY><FORM></HTML>&quot;;



cardWindow = open(&quot;&quot;,&quot;cardWin&quot;,&quot;width=450,height=350,resizable=1&quot;);



with (cardWindow.document)
{
open();
write(pageContent);
close();
}

}

//-->
</SCRIPT>

<INPUT type=button value=&quot;New Window&quot; onclick=newWin();>

</BODY></FORM></HTML>
 
&quot;write(pageContent);
close();&quot;
you are not waiting for the utton to be pressed !!!!



 
What?

Is the onClick event not associated with the button. Did you test this?

thanks
 
You may want to break this into two files as follow:

File 1:
=======

<!-- This is file: testOpen.html -->
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<HTML>
<HEAD>
<TITLE>New Window Test</TITLE>

<SCRIPT language=JavaScript>
<!-- Hide from old browser

// Open a new window
function newWin()
{
url = &quot;testClose.html&quot;
newWindow = window.open(url)
}

//-->
</SCRIPT>

</HEAD>

<BODY>

<FORM>
<INPUT TYPE=&quot;BUTTON&quot; VALUE=&quot;New Window&quot; onClick=&quot;newWin()&quot;>
</FORM>

</BODY>
</HTML>
<!-- End of file: testOpen.html -->


File 2:
=======

<!-- This is file: testClose.html -->
<HTML>
<HEAD>
<TITLE>Close Parent Test</TITLE>
</HEAD>
<BODY>

<script langauge=&quot;JavaScript&quot;>
<!--

// close parent window.
opener.close();

//-->
</script>


<FORM>
</FORM>

</BODY>
</HTML>
<!-- End of file: testClose.html -->


You may want to change the files testOpen.html and testClose.html to what ever file name you want to call.
 
Thanks khue,
is there any way of turning the confirmation closure form?

Thanks

Bakunin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top