Forum Moderators: open
If the user left clicks the download link it will open the mp3 (usually in a blank page with quick time) which is retarded. I want to force the people to use the links correctly (it's not REALLY that difficult). The same thing with the preview links. You left click to preview and right click to download.
However the script I have made only half works. It will alert the user they are umm, doing the wrong action. However it will still execute their original left/right click which EVER after I had thrown in a return false.
How do I get this to work correctly in the behavior I am hoping for?
<script type="text/javascript">
function download() {alert("This is a download link, right click to save the file!"); return false;}
function preview() {alert("This is a preview link, left click to preview the song!"); return false;}
</script>
<script type="text/javascript">
function download() { alert("This is a download link, right click to save the file!"); return false;}
function preview() { alert("This is a preview link, left click to preview the song!"); return false;}
</script><a href=#" onclick="download();return false;">Download</a>
<a href=#" OnContextMenu="preview();return false;">Preview</a>
I was half expecting someone to point out the fact that oncontextmenu attribute is not valid on anchors when run through the W3C valiudator.
I haven't had enough time (due to annoying homework) but here is the file I was messing with to find a way around the problem. BM - note I just read your post and will work with what you mentioned when I return from class in...ug -four hours. :(
Anyhu here is my file I was messing with earlier!
<html>
<head>
<script type="text/javascript">
<!--
function OpenLink(theURL) {window.open(theURL);
document.oncontextmenu = newFunction("returnfalse")
}
function download() {alert("This is a download link, right click to save the file!"); return false;}
function preview() {alert("This is a preview link, left click to preview the song!"); return false;}
//-->
</script></head>
<body>
...which I call like this:
<a href="javascript:OpenLink('http://www.webmasterworld.com.com/')">Site Name</a>
oncontextmenu = newFunction("returnfalse")
<a href="javascript:OpenLink('http://www.webmasterworld.com.com/'); oncontextmenu=newFunction('returnfalse')">Preview</a>
<a href="javascript:OpenLink('http://www.webmasterworld.com.com/'); onclick=newFunction('returnfalse')">Preview</a></body>
</html>
Remember I'm just trying to get the oncontextmenu to work without using it as an attribute on the anchor! I figured using a javascript link would be able to achieve this though I have never really tried something like this to the extent you see.
John