Forum Moderators: open
I have created a window handle in the document of window 1 with the following javascript.
wH = window.open('page.htm','pWin',features);
Then I link to document 2 from document 1 of window 1. It loads the document 2 into window 1. From document 2 I want to be able to close window 2, if it is open, and then open a new window with different features in its place.
I have tried the following, but I get and error "wH is undefined".
wH.close();
The problem I have is that the variable wH was created by document 1 and document 2 doesn't know anything about the variable wH.
How can I pass this handle to document 2? If I can't pass this handle, can I access it in any other way?
As for a workaround... it would have to be some client-side code to read the window, as it obviously is a client-side window.... Thus, JavaScript seems the obvious one, but after reading MSDNs window object properties there nothing in window to allow this.
For security reasons, (message queueing for one), scripts are not allowed to directly access the window, so I doubt there are any technologies that would allow this... seems like a big security hole if they did to me.
Unfortunately, features of windows that have been opened previously by window.open aren't overwritten when you pass in new features to the same window. For instance, I can get my content to load within the window, but if my content has changed size and I pass in new features to a window.open method such as height and width it doesn't override the original height and width of the window.
I have tried to work around this by passing in the height and width as a URL parameter and dynamically writing a resize function with server side scripting that uses window.resizeTo and I get an "access denied" error when the function is called from the onload method of the body tag.
Could there be a work around for this, such as calling the function sooner or later?
window.open('mypage.htm','pW','width=500,height=400,scrollbars');
This is the first call to open a window.
The second call may look like this.
window.open('mypage.htm','pW','width=650,height=400,scrollbars');
If I make this call without closing the window pW the pW window will not take on the new width. If I close the window first ane then re-open it, it will have the new features. I want to be able to resize the popped-up window without closing it first. Because I can't close it from another page, but I can call window.open again with the same window name to get new content in the window.
I tried using PHP/JavaScript to dynamically create a resize function based on the height and width passed in the query string.
window.open('mypage.htm?wWidth=650&wHeight=400,'pW','width=650,height=400,scrollbars');
Now I can use these variables passed to write a Javascript Function in the window I just opened. The function would look like this before being parsed by the PHP processor.
function ResizeWindow(){
window.resizeTo(<?=$wWidth?>,<?=wHeight?>);
}
When the page loads I call the function like this.
<body onload="ResizeWindow();">
I get the error "Accessed Denied".
If I can't find a solution, I will have no choice but to close the opened window before I load in a new document and then make them re-open it. :(
I ran the page, created new window appropriately sized. I altered the code, reloaded, keeping window open, and it appropriately sized.
my stuff (prob. same as yours):
...test.htm...
<script language="Javascript">
wH=window.open('test.php?w=500&h=300','pW','width=650,height=600,scrollbars');
</script>
...test.php...
<?php
echo ("<script language='JavaScript'>");
echo ("window.resizeTo('".$_GET['w']."','".$_GET['h']."');");
echo ("</script>");
?>
<p> Hey folks, content text! </p>