Mick White wrote:
K. S. wrote:
hi guys,
this code works fine in IE but doesnot work in opera. the page just
reloads to test.html# in opera.
can anyone help? thanks.
-----------------------------------------------------------------------
<html>
<head><script language="JavaScript" type="text/JavaScript">
function disco() {
if( confirm('are you sure?') )
window.confirm method requires two arguments
function disco(){
if(confirm('are you sure?','') ){.....
No, it really doesn't: <url:
http://devedge.netscape.com/library/...w.html#1201914
/>
It actually doesn't even require one argument in Internet Explorer: <url:
http://msdn.microsoft.com/workshop/a...ds/confirm.asp
/>
Although Gecko-based browsers generate an error and Netscape 4 presents a
confirm dialog that says "undefined" if you attempt to call confirm() without
any arguments. Regardless, that wasn't his problem. He explicitly said that
the link "reloads <the url>#". This is a major hint that he's got the
following code:
<a href="#" onClick="javascript:disco()">Déconnexion</a></body>
and that he isn't returning false from the onclick event:
<a href="#" onclick="disco();return false;">Google</a>
Of course, this isn't really what he wants because regardless of what the
user chooses the link won't be followed. What he wants is for the link to
force the user to answer yes or no, so:
<script type="text/javascript">
function disco() {
return confirm("Are you sure?");
}
</script>
<a href="http://wwww.google.com" onclick="return disco();">Google</a>
Is what he really wants.
Now you've got a fully functional link regardless of whether the browser
supports or has JavaScript enabled. And if JavaScript is enabled, it will
prompt the user "Are you sure?". Clicking the affirmative button will result
in true being returned to the event and the HREF will be followed. Clicking
the negative button will result in false being returned to the event and the
HREF will not be followed.
--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ -
http://jibbering.com/faq