Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1386 How can I extend the "No Right Click" script to play a sound at the same time as denying the right click?

You are here: irt.org | FAQ | JavaScript | Sound | Q1386 [ previous next ]

The following extends the answer given in FAQ 969:

<head>

<script language="JavaScript1.1"><!--
var debug = true;
function right(e) {
    if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2)) {
        playSound();
        return false;
    }
    else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3)) {
        playSound();
        var mywin = window.open('about:blank','','width=100;height=100');
        mywin.close();
        return false;
    }

    return true;
}
document.onmousedown=right;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
window.onmousedown=right;
//--></script>

</head>

<body>

<script language="JavaScript"><!--
var can_play = false;

var mimetype = 'audio/midi';

if (navigator.mimeTypes) {
    if (navigator.mimeTypes[mimetype] != null) {
        if (navigator.mimeTypes[mimetype].enabledPlugin != null) {
            can_play = true;
            document.write('<embed src="sound.mid" hidden=true loop=false autostart=false>');
        }
    }
}

function playSound() {
    if (document.embeds && can_play) {
        if (navigator.appName == 'Netscape')
            document.embeds[0].play();
        else
            document.embeds[0].run();
    }
}
//--></script>

<!-- place your content after this line -->

<p>
<img src="picture.gif" width="100" height="100">
</p>

<p>
some text
</p>

<p>
<a href="somewhere.htm">text link</a>
</p>

<!-- and before this line -->

<script  language="JavaScript1.1"><!--
// to prevent right click on images include:
for (var i=0; i<document.images.length; i++) document.images[i].onmousedown=right;

// to prevent right click on links include:
for (var i=0; i<document.links.length; i++) document.links[i].onmousedown=right;
//--></script>

</body>
</html>

©2018 Martin Webb