JavaScript

Moderators: None (Apply to moderate this forum)
Number of threads: 2057
Number of posts: 5155

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Query User Posted by GameFreak7744 on 16 May 2006 at 4:58 PM
Is it possible to use Java Script to question if a user really wants to follow a link, and then follow it if they say yes, and cancel if they say no?

Thanks in advance for any help.
~Joey~
Report
Re: Query User Posted by zibadian on 16 May 2006 at 8:52 PM
: Is it possible to use Java Script to question if a user really wants to follow a link, and then follow it if they say yes, and cancel if they say no?
:
: Thanks in advance for any help.
: ~Joey~
:
Yes, it's possible. You can do this by setting the onclick() event of the links, or by placing a function call in the link's href. In the javascript function you then ask the user to proceed. If he doesn't do nothing, otherwise open the page using the window.location property. See http://www.w3schools.com/htmldom/obj_win_location.asp for more info and examples.
Report
Re: Query User Posted by GameFreak7744 on 19 May 2006 at 5:38 PM
: Yes, it's possible. You can do this by setting the onclick() event of the links, or by placing a function call in the link's href. In the javascript function you then ask the user to proceed. If he doesn't do nothing, otherwise open the page using the window.location property. See http://www.w3schools.com/htmldom/obj_win_location.asp for more info and examples.
:

Thanks for the help.
I'm pretty clueless about this whole thing, so please bear with me. If I leave in the href of the links, then they just follow normally, and if I remove it they stop acting like links, with the mouse pointer not changing when placed over them, and no formatting changes.
Am I doing something wrong?
Report
Re: Query User Posted by mac_doggie on 5 Jul 2006 at 1:18 PM
: : Yes, it's possible. You can do this by setting the onclick() event of the links, or by placing a function call in the link's href. In the javascript function you then ask the user to proceed. If he doesn't do nothing, otherwise open the page using the window.location property. See http://www.w3schools.com/htmldom/obj_win_location.asp for more info and examples.
: :
:
: Thanks for the help.
: I'm pretty clueless about this whole thing, so please bear with me. If I leave in the href of the links, then they just follow normally, and if I remove it they stop acting like links, with the mouse pointer not changing when placed over them, and no formatting changes.
: Am I doing something wrong?
:

If you don't have an href an anchor stops acting like a link indeed. so why use the onclick You can also put JavaScript in the href by typing JavaScript: in it see my example below:

Try this:
<a href="JavaScript:if(confirm('really wanna go there?')) document.location.href='http://www.google.com'">Go to google</a>



-mac-
mailto:mac_doggie@hotmail.com
the Netherlands...





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.