Click to See Complete Forum and Search --> : closing a popup from the parent
chickenpants
09-04-2003, 01:10 PM
i'm still relatively new to this, but here goes.
i have a popup window created with the following code:
function styleWindow(url) {
var stylePop=window.open(url,"stylePop","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=250,height=200, left=200,top=100");
stylePop.focus();
}
it loads a page with a form that submits information and forces a reload of the parent page with this function driving the form submit:
<script language="JavaScript">
function styleSelect() {
document.style.submit();
setTimeout('opener.window.location.reload()',0100);
}
</script>
that all works fine, what i need now though is code that will automatically close the popup window when the user clicks on a link in the parent window to go to a new page. any help or thoughts are appreciated.
cp
Charles
09-04-2003, 01:15 PM
function styleWindow(url) {
stylePop = window.open(url,'stylePop','width=250,height=200,left=200,top=100');
stylePop.focus();
window.onunload = function () {if (stylePop && !stylePop.closed) stylePop.close()}
}
But does your site work for the 13% of us who do not use JavaScript?
chickenpants
09-04-2003, 01:44 PM
first, i haven't yet dealt with the non javascript version of this, and probably won't. not my call.. javascript is a required component to view the site i'm working on.
that being said, the code above does indeed do what it says, but maybe i should've been more specific.
the popup form allows the user to choose between multiple stylesheet options. when submited, the parent window refreshes with the new style sheet selection so the user can see the results. the idea is that the popup will remain open (to allow multiple submits) and only when the user moves from the page they are on currently to another page does the popup window close. the code added above causes the popup to close on submit because the browser refresh calls the onUnload/onLoad methods. problematic.
if i had my way i wouldn't use popups at all.. but again, not my call.
is this possible?
Charles
09-04-2003, 02:02 PM
Originally posted by chickenpants
is this possible? Both possible and quite simple. It requires the addition of at most 44 characters. But I'm one of those people who you do not use JavaScript and I'm rather insulted that you are intentionally making a page that is not accessible to me.
And I should point out that it is also thereby inaccessible to persons with certain disabilities and hence may run you afoul of certain accessibility laws.
chickenpants
09-04-2003, 02:17 PM
i did my best to fight for the simple version of this style changer which required no javascript at all and ran reliably cross browser. but those higher up the chain decided to go with this overly complicated and at best questionable process.
i'm not a fan of javascript, popups, or frames. and as i'm the one that also has to ensure compliance with section 508, this bugs me. but i'm just a contracter and apparently not worth listening to. i'm just trying to give them what they asked for, regardless of what it's actually what they need.
if you could help me do that or point me in the right direction that'd be great.
cp
Aronya1
09-04-2003, 02:23 PM
If I understand your explanation properly, the user is going to see the result of the change of stylesheet BEHIND the popup window. If that is correct, why not let them kill the popup on their own when they are done choosing the style? They'll have to click around it to go to the parent page, anyway...
Otherwise...
I'm not a js coder, but maybe there is a way to add some sort of "onpageout" function to the parent page that would also kill the popup?
Good luck
Khalid Ali
09-04-2003, 02:24 PM
use partial code from charles solution like this
<a href="#" onclick="if (stylePop && !stylePop.closed) stylePop.close(); return false;">CLick to close</a>
Charles
09-04-2003, 02:25 PM
If you promise that the rest of the page transitions gracefully then just add to the FORM start tag...
onsubmit="window.onunload = function () {}"