SongBox
SongBox

Reputation: 691

How do you show a JS alert only once?

I want a message to pop up to alert users of LT IE8 that they should really upgrade their browser or they won't have the best possible web experience. However I only want this to pop up on their first visit to my site, not on every page refresh.

Is there a way to do this?

Thanks in advance.

Upvotes: 1

Views: 2480

Answers (5)

Etienne Perot
Etienne Perot

Reputation: 4882

Store a cookie to remember the fact that they have received the alert. You can do this using document.cookie, or using some of the JavaScript libraries out there that let you do that more easily.

By the way, alerts are evil and annoying. People will probably have a better experience (and thus more likely to be willing to change their browser) if you use something less intrusive, like an in-page banner.

Upvotes: 6

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324840

I would not want an alert in my face, especially not if there's the chance you might not know what you're doing (which is likely if you're kicking out IE8 users) and might accidentally trigger Compatibility View, because this would cause even IE10 users to get your anti-IE8 message.

I woud recommend using:

<!--[if lte ie 8]>
    <p>You are using an out-dated version of Internet Explorer. Please update.</p>
<![endif]-->

In combination with:

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

Upvotes: 2

JaredMcAteer
JaredMcAteer

Reputation: 22555

You might want to consider adding the IE6 countdown upgrade notification. I used it on the site I work for and just changed the code to read if lte IE 7 rather than if lt IE 7

http://www.ie6countdown.com/join-us.aspx

Upvotes: 0

Paul
Paul

Reputation: 2515

You could store the a variable as a cookie and only run the pop up if the cookie doesn't exist. Alternatively, you could store visitor data in a database and check if its their first view of the page or not.

Upvotes: 0

mdprotacio
mdprotacio

Reputation: 842

You may use cookies. If a cookie is set, you don't alert them again; if the cookie is not set, you alert them. If it is an HTML5 capable browser, I believe you can store data on the browser itself and in there, you can store some indicators needed for the problem.

Upvotes: 0

Related Questions