Forum Moderators: open
However, I thought it would be neater to have the index page automatically produce the pop-up and then close itself down, or maybe minimize and display a message along the lines of 'Thanks for visiting'.
If this is possible, I could have a problem for anyone trying to access the site without the Javascript plugin. I therefore thought about using a Javascript plugin detector, which would check for browser compatibility first. It would then then either open up a pop-up window and close the original window or, if the Javascript plugin is not available, would write out a message in the existing window, stating that this plugin is needed. This window could also offer to open up the main site without using Javascript, I guess.
I have a script which opens up a pop-up from the index file, which works fine. I then added the script below in the pop-up window, in an attempt to shut down the index window. It works (in IE), but opens up multiple copies of the pop-up window.
Does anyone have a script which may do the job, or have any thoughts about ways around the problem?
Thanks.
<script>
if (!opener.closed && opener.location){
opener.location.href="index.htm";
opener.opener = top
opener.parent.window.close();
}
</script>
The problem with openg multiple windows is because of the lines, I think:
opener.location.href="index.htm";
opener.opener = top
I already had a script which loaded the pop-up window automatically, but this was overly complicated and used cookies, so I have now changed this to the onLoad command, as you suggested.
Re the non-Javascript enabled browsers, I will modify the html page accordingly. Thanks for the suggestions.
Re the multiple windows, if I remove the two lines of script you suggest, then I have the old problem where a question is asked before the parent window is closed. This is not really what I wanted and the original script closes the window nicely.
Having re-tested it in IE 6, I notice that sometimes it works perfectly and other times opens up two or more windows (sometimes as many as nine!). Meanwhile, it is fine all the time in Netscape 7. Any ideas how to make it reliable in IE?
While this is sound logically, there is actually a pragmatic way of testing for JS, without using JS (in case it is turned off or not present). You set up a page with a single line of script -- window.location.href="page_to_go_to_if_it_works.htm" -- plus any stuff you want them to see if it is turned off. :)
Jordan
"...set up a page with a single line of script -- window.location.href="page_to_go_to_if_it_works.htm" -- plus any stuff you want them to see if it is turned off..."
Agreed. That is what I meant by:
However, I think there is a way to refine it to produce a faster response, as MonkeeSage hints: Put the javascript function call in your <head> section, so it runs as the page loads instead of after loading.
Just wanted to add that you can also use the <noscript> [w3.org] tag to show a message about the plugin you require to users who have turned JavaScript off.
If there's no way around the multiple pop-up windows from IE (see above), is it possible to minimise the parent window, rather than close it? Maybe this could then be used in conjunction with a browser detection script, so that IE users minimise and pop-up, whilst Navigator users close and pop-up?
Any suitable scripts would be welcomed!