Welcome to WebmasterWorld Guest from 54.160.131.144

Forum Moderators: open

Message Too Old, No Replies

Modified Javascript Detection & Pop-Up

How to modify JS detection to include additional features.

     

draco

9:51 am on Aug 23, 2003 (gmt 0)

10+ Year Member



I have designed a web site, which I would like to open in a window of a set size and without toolbars etc., so I decided to use the Javascript pop-up method. In the past, I have used a simple html page as the index page, from where the surfer clicks a button to enter the main site. The pop-up is instigated from the button.

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>

ShawnR

10:13 am on Aug 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A few thoughts:

  • Easy to automate - just use the "onload" attribute of the body tag to run your javascript.
  • If javascript is not supported or turned on in the browser, the html page will be what your visitor sees, so just use that.
  • You can't test for javascript and if not there show something else... If javascript is not supported your test would not run.
  • I would not think of javascript as a plug in. It is part of the browser. Some users deliberately turn it off for various reasons, and some browser agents, such as Search Engine bots or browsers for vision impaired don't support javascript, so it may come across as rude or uninformed to put up a sign saying 'please download the javascript plugin'.

The problem with openg multiple windows is because of the lines, I think:

opener.location.href="index.htm";
opener.opener = top

draco

2:23 pm on Aug 23, 2003 (gmt 0)

10+ Year Member



Shawn,

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?

tedster

6:02 pm on Aug 23, 2003 (gmt 0)

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Unless your javascript has opened a window, it cannot close that window without getting the end user's permission. This is a standard security precaution built into javascript.

MonkeeSage

6:10 pm on Aug 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can't test for javascript and if not there show something else... If javascript is not supported your test would not run.

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

draco

6:21 pm on Aug 23, 2003 (gmt 0)

10+ Year Member



Thanks for your suggestion, Jordan. I'll certainly consider this as an option.

Tedster, I am aware that there is an in-built mechanism to prevent this, but check out the script I used and it DOES close the parent window, even though it was not popped up using Javascript....

ShawnR

11:19 pm on Aug 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



"...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:

  • Easy to automate - just use the "onload" attribute of the body tag to run your javascript.
  • If javascript is not supported or turned on in the browser, the html page will be what your visitor sees, so just use that

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.

garann

6:04 pm on Aug 25, 2003 (gmt 0)

10+ Year Member



Hi draco,

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.

draco

4:19 pm on Aug 26, 2003 (gmt 0)

10+ Year Member



Thanks for the tip, Garann. I'll bear that in mind.

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!

 

Featured Threads

Hot Threads This Week

Hot Threads This Month