homepage Welcome to WebmasterWorld Guest from 54.197.15.196
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Modified Javascript Detection & Pop-Up
How to modify JS detection to include additional features.
draco

10+ Year Member



 
Msg#: 541 posted 9:51 am on Aug 23, 2003 (gmt 0)

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

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 541 posted 10:13 am on Aug 23, 2003 (gmt 0)

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

10+ Year Member



 
Msg#: 541 posted 2:23 pm on Aug 23, 2003 (gmt 0)

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

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



 
Msg#: 541 posted 6:02 pm on Aug 23, 2003 (gmt 0)

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

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 541 posted 6:10 pm on Aug 23, 2003 (gmt 0)

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

10+ Year Member



 
Msg#: 541 posted 6:21 pm on Aug 23, 2003 (gmt 0)

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

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 541 posted 11:19 pm on Aug 23, 2003 (gmt 0)

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

10+ Year Member



 
Msg#: 541 posted 6:04 pm on Aug 25, 2003 (gmt 0)

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

10+ Year Member



 
Msg#: 541 posted 4:19 pm on Aug 26, 2003 (gmt 0)

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!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved