Alerts: Only one wanted - How to?

This is a discussion on "Alerts: Only one wanted - How to?" within the JavaScript Forum section. This forum, and the thread "Alerts: Only one wanted - How to? are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Dec 17th, 2006, 01:44
Junior Member
Join Date: Sep 2005
Location: kNot in Kansas
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Alerts: Only one wanted - How to?

(bear w/ me, there's a point coming up in paragh2)
this is kinda crazy-- i've been doing html for almost 10 years-- an last night was the first that the whole javascript thing finally came to me. don't get me wrong-- i've used it tons of times, and even written stuff-- like the Hide-a-div / css display none thing that's quite popular, etc.-- but for some reason-- it never really seemed to make sense-- blah- blah-- point is, i think i might finally have my head around it.

for one thing-- i never noticed that event handlers are actually an HTML thing-- sorta. kind of like the female to javascript's male, so to speak, right? (only the gods would know why). so i've got experience, but i'm going to ask some really dull questions about javascript here (and probably in the future, depending on what kind of response i get from the crowd. so i hope the martini's are good tonight)

the INQUIRY
i only want to have one alert popup instead of every time someone passes over the anchor eventhandler (wow! it's fun to say event handler!). it is annoying enough w/out it happening over and over. is there a way to make it do only one per visit-- even if someone comes back to the page again before they finally leave the site?

the code is essentially:
Code: Select all
<script type="text/javascript">
<!--
function pop() {
    alert("hey you! eggburger! farts!");
}
-->
</script>

<!-- snipped -->
<a href="someanchortarget" mouseout="pop()">sometext</a>
Reply With Quote

  #2 (permalink)  
Old Dec 17th, 2006, 11:46
Reputable Member
Join Date: Jul 2006
Location: Scotland
Age: 22
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to snow
Re: Alerts: Only one wanted - How to?

I don't think there's a way to do it between pages with JavaScript - that I can remember anyway... I think you'd need some kind of session.

On the same page, to make it pop up only once you could do something like...

Code: Select all
 function pop() {
  if (done!=1) {
        alert("hey you! eggburger! farts!");
    done=1;
  }
}
Just off the top of my head after I haven't used it for a while - so there are probably much better solutions out there!
Reply With Quote
  #3 (permalink)  
Old Dec 17th, 2006, 14:12
Ryan Fait's Avatar
SuperMember

SuperMember
Join Date: May 2006
Location: Las Vegas
Posts: 3,786
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Alerts: Only one wanted - How to?

You can use cookies to do this, but more importantly, you need to know that JavaScript and HTML are completely separate. You should never have JavaScript inside an HTML document. Use the script take to link externally.

The document.getElementById("something"); is your friend. Learn to use and love unobtrusive JavaScript.
Reply With Quote
  #4 (permalink)  
Old Dec 17th, 2006, 16:53
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Skype™ to ukgeoff
Re: Alerts: Only one wanted - How to?

Quote:
Originally Posted by snow View Post
I don't think there's a way to do it between pages with JavaScript - that I can remember anyway... I think you'd need some kind of session.

On the same page, to make it pop up only once you could do something like...

Code: Select all
 function pop() {
  if (done!=1) {
        alert("hey you! eggburger! farts!");
    done=1;
  }
}
Just off the top of my head after I haven't used it for a while - so there are probably much better solutions out there!
Be aware of a problem here that often catches out people new to JavaScript and other similar languages for that matter.

The variable you are setting, 'done' only exists inside the function, so once the function finishes, so the variable 'done' no longer exists. You would need to define the variable globally.
Reply With Quote
  #5 (permalink)  
Old Dec 17th, 2006, 21:03
Reputable Member
Join Date: Jul 2006
Location: Scotland
Age: 22
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to snow
Re: Alerts: Only one wanted - How to?

Sorry I didn't include the declaration - I was just psuedo coding...

thanks for the spot!
Reply With Quote
Reply

Tags
any, anymore, can, complain, fun, jesus, not, okay, only, tags, this

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Please help me add some random alerts to my code meddow JavaScript Forum 0 Nov 24th, 2006 01:04
Wanted to say Hi! dchesterton Introduce Yourself 8 May 8th, 2006 18:43
Hi everyone, I'm new here and just wanted to say hello Saleem Introduce Yourself 6 Nov 30th, 2005 13:50
Else and alerts chuckcampbell JavaScript Forum 8 Oct 5th, 2005 18:44
Just Wanted to Say Hello hostlegal Introduce Yourself 2 Jun 27th, 2005 09:54


All times are GMT. The time now is 22:20.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43