|
-
Feb 12th, 2005, 08:35 AM
#1
Thread Starter
Hyperactive Member
Very simply maybe
Hi!
I am unable to detemine how to do the following:
I have a basic html <ahref link:
Code:
<a href="test.php?id=1">Test</a>
Now when user clicks on the above links it must be confired weather he wants to go at it or not...i mean just a yes, no box, if user presses yes then he's taken to that link else just stay in there.
How can i achieve thus using javascript ?
Thanks!
Tapan Bhanot,
CEO, Avis Software.
Website: www.avissoftware.com
-
Feb 12th, 2005, 09:52 AM
#2
Frenzied Member
Re: Very simply maybe
Something to the extend of:
Code:
function takeme(url){
if (confirm("Are you sure?")) {
location.href=url;
} else
{
//clicked cancel - do nothing
}
}
the something like
Code:
<a href="javascript:takeme('http://google.com');">click</a>
On a sidenote.. I think if the user clicks on a link he's pretty sure he wants to go there so this script seems abit useless to me, sorry.
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Feb 12th, 2005, 09:57 AM
#3
Re: Very simply maybe
No! Bad Jop! 
This solution is inaccessible. It's better to do:
<a href="target.html" onclick="return confirm("Really?")">Hit Me!</a>
This way, users without JavaScript can use the link. (They don't get the confirmation though.)
Of course, it would be even better not to put the script inline, but attach it from an external JS file.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 12th, 2005, 10:07 AM
#4
Re: Very simply maybe
A better way would be to use the onclick event. Its also easier and means the link will still work even if Javascript is disabled:
Code:
<a onclick="return confirm('Are you sure?')" href="test.php?id=1">Test</a>
-
Feb 12th, 2005, 10:11 AM
#5
Thread Starter
Hyperactive Member
Re: Very simply maybe
Hi!
Thanks for the help. Can i have yes/no buttons as Proceed/Cancel ?
Thanks!
Tapan Bhanot,
CEO, Avis Software.
Website: www.avissoftware.com
-
Feb 12th, 2005, 10:29 AM
#6
Re: Very simply maybe
No. Some browsers will use Yes/No, other OK/Cancel, but you have no control over it.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 12th, 2005, 10:33 AM
#7
Frenzied Member
Re: Very simply maybe
Oi oi thanks for correcting me CornedBee I should've known better!
To make up for my mistake, the unobtrusive version:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<head>
<title>Link confirmation</title>
<script type="text/javascript">
function confirmLink(url){
if(confirm("Are you sure?"))
location.href=this.getAttribute("href");
else
return false;
}
var addOnclickHandlers = function(){
var links = document.getElementsByTagName("a");
for(var x=0;x<links.length;x++){
if(links[x].className == "confirm")
links[x].onclick = confirmLink;
}
}
window.onload = addOnclickHandlers;
</script>
</head>
<body>
<a href="http://google.com" class="confirm">google</a>
</body>
</html>
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Feb 12th, 2005, 11:39 AM
#8
Thread Starter
Hyperactive Member
Re: Very simply maybe
Hi!
Thanks for all the suggestions and comments. I used visualAd's code which is working cool! 
Thanks!
Tapan Bhanot,
CEO, Avis Software.
Website: www.avissoftware.com
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|