Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I cancel a link after it has been clicked? 1

Status
Not open for further replies.

nomofoxpro

Programmer
Sep 14, 2000
13
US
I need to cancel a link after it has been clicked using javascript. There must be some code that I can place in the onClick event of the link that will cancel it from bringing the user to the next screen. I am trying to force the user to right click on the link in order to download office documents and not have them open up in the browser window. If seems that the HTTP Header Content-Disposition does not work in IE 5.5 so I have to do it this way.

Thanks
 
something like this, but you need to name your links if you want the link to stay in view (I think):

<script>

function cancelNav(obj)
{
var tmp;
tmp = obj.href
obj.href=&quot;#&quot;+obj.name
setTimeout(function(){obj.href=tmp},1)
}

</script>

</head>

<body>

<a hidefocus href=&quot; name=&quot;jive&quot; onclick=&quot;cancelNav(this)&quot;>darg</a>
jaredn@subdimension.com -
 
Old message I know but a simpler way of achieving this is simply to include an onCLick event to the link as follows:

Code:
<SCRIPT LANGUAGE=&quot;JAVASCRIPT&quot;>
function DownloadMsg()
{
 alert(&quot;To download this file you need to right-click on the link and select Save Target As...&quot;);
 return false;
}
</SCRIPT>

<A HREF=&quot;wordfile.doc&quot; onClick=&quot;return DownloadMsg();&quot;>myWordDocument.doc</A>
Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top