Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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?

irt.org | Knowledge Base | JavaScript | Event | Q1274 [ previous next ]

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?

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>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.