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

Q1274 How can I prevent the user from opening the page in another window, which in some browses can be done by pressing shift-left-mouse?

You are here: irt.org | FAQ | JavaScript | Event | Q1274 [ previous next ]

Try:

<head>

<script language="JavaScript1.1"><!--
var debug = true;

function left(e) {
    if (navigator.appName == 'Netscape' && (e.modifiers & Event.SHIFT_MASK) && (e.which == 1)) return false;
    else if (navigator.appName == 'Microsoft Internet Explorer' && window.event.shiftKey && (event.button == 1)) {
        alert('Denied');
        return false;
    }

    if (debug) alert('Allowing mousedown event to proceed...');
    return true;
}

document.onmousedown=left;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
window.onmousedown=left;
//--></script>

</head>

<body>

<!-- 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 shift-left click on images include:
for (var i=0; i<document.images.length; i++) document.images[i].onmousedown=left;

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

</body>
</html>

©2018 Martin Webb