PDA

View Full Version : Error message Using External .JS files



java55
04-13-2010, 01:59 AM
Hello everyone !!! This is the problem I'm having:

I'm trying to incorporate a Right-Click-Disable script into my webpage by using an external .js file since I have several pages in my website. The thing is that when I run it I get an INVALID CHARACTER error pointing to Line 1 Character 1 of the .js file and I just can't seem to find the error. Here are the HTML and .js files I'm using (in an empty webpage to run as test) :
-----------------------
THE HTML FILE:

<html>
<head>
<script type="text/javascript" src="disablemouse.js">
</script>

</head>

<body>
</body>
<p>

<body>
</body>
</html>

-------------------------
THIS IS THE disablemouse.js FILE:

<!--
//Disable right click script III- By Renigade(renigade@mediaone.net)
//For full source code, visit http://www.dynamicdrive.com
var message="";
///////////////////////////////////
function clickIE() {if (document.all) {(message);return
false;}}
function clickNS(e) {if
(document.layers||(document.getElementById&&!document.all))
{
if (e.which==2||e.which==3) {(message);return false;}}}
if (document.layers)
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}
document.oncontextmenu=new Function("return false")
// -->

-------------------------

I'm using Front page as my webpage editor. When I run it without the .js file it works perfect, the problem comes when I use the external file approach.

Thanks.

java55
04-13-2010, 03:56 AM
sos - anybody please!!!!
Read previous posting.

Thanks

djr33
04-13-2010, 04:12 AM
Allow more than 2 hours to pass. There's no point in bumping the thread so early. Someone will help you when they have a chance. Also, unanswered threads are more likely to get responses, so posting more will run the risk of having users think the question is already answered if there are replies.

Nile
04-14-2010, 02:20 AM
Djr33 - I'd say 24 hours... Try deleting the <!-- and // -->

djr33
04-14-2010, 02:34 AM
Yes, to be clear-- I meant that bumping WITHIN 2 hours is very bad. Waiting 24 (at least) is normal/good.

java55
04-14-2010, 02:36 PM
Thanks, I tried that too and nothing happens.

djr33
04-14-2010, 05:24 PM
The .js file should look like this:

//Disable right click script III- By Renigade(renigade@mediaone.net)
//For full source code, visit http://www.dynamicdrive.com
var message="";
///////////////////////////////////
function clickIE() {if (document.all) {(message);return
false;}}
function clickNS(e) {if
(document.layers||(document.getElementById&&!document.all))
{
if (e.which==2||e.which==3) {(message);return false;}}}
if (document.layers)
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}
document.oncontextmenu=new Function("return false") (as Nile suggested).
If it still doesn't work, then post a link to your page so we can see what's wrong. With just the code it's hard to tell what is not correct.



Also, this script is basically useless. More importantly, it's annoying. There is no case where you can actually stop people from doing things on the website (like saving images, viewing the source code, etc), so adding this will just annoy people because it will stop them from doing normal things (like right click > bookmark this page, or right click > open link in new window). You can use it if you want, but usually it's a mistake.

The only times when this is actually useful is when you want to do something ELSE when you right click, such as adding a custom right click menu for a web-app. But even then there are problems with compatibility, etc.