Jump to content

close browser help


deejaybet

Recommended Posts

im back again with another problem... dont know if this can b solved but ive found a script that when the user clicks on it, it closes the browser for example i give the user a choose of either enter the site or leave it.... problem with the script is that it only seams to work for IE... anyone know a cross-browser version of it... its only a link script... im sure ive seen it somewere else before... i need it as a link only.. no buton form etc.. just a normal text/link form

<a href="javascript:window.close()">Leave</a>

Link to comment
Share on other sites

Let me guess, it works for IE but you are prompted before the window closes. The window.close() will work for a something like a popup window but not for the entire browser instance in certain browsers.Typically, you really don't want people to "leave" your site. Its like a car salesmen asking you if he can help you and then him saying "leave" when you say "I'm just browsing thanks".But, if you want to do that, then just link them to w3schools.com or your favorate search engine.P.S. your syntax is correct.

Link to comment
Share on other sites

Every so often that syntax will fail (like one in a thousand). It will try and find a page called java script:.... This is in IE btw.I would suggest this

<a href="#" onclick="window.close()">Leave</a>

This should work in all browser providing the user has javascript enabled.

Link to comment
Share on other sites

a better syntax for the alternate solution aspnetguy offers is:

<a href="javascript: void(0);" onclick="window.close()">Leave</a>

Link to comment
Share on other sites

IE still goofs on a href="java script: anything" sometimes, not often mind you.I develop apps with lots of client side code and have seen this issue a lot in my development.

are people annoyed by the # appearing in the URL and confusing them. I had a client once that was VERY irritated with that techique. Aren't people fun? :)I hadn't hear of the issue, sparatic as it may be) you mention. It interesting to note though. :)
Link to comment
Share on other sites

it doesn't happen often, very rare actually, but it has happened. So I guess to save peopl ebeing irritated by it you could use your method...lol.Why was he irritated...if something happens with the javascript I am surprised he noticed.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...