当一个人右键单击时,你如何使javascript重定向?甚至可能吗?
var message="MESSAGE TO USER"
function clickIE4(){
if (event.button==2){
alert(message);
window.open("site.com/whatever.php");
return false;
}
}
function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert(message);
window.open("site.com/whatever.php");
return false;
}
}
}
if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}
document.oncontextmenu=new Function("alert(message);return false")
我正在尝试将 window.open("site.com/whatever.php")插入脚本中,但没有成功。
编辑
我希望在警报框关闭时进行重定向。很抱歉之前没有说清楚。
更改
if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}
自
if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}
else {
document.onmousedown = function (e) {
if (e.button == 2)
{
alert("Ouch! that hurts. Please do not right click!");
setTimeout(function() { location.href="http://www.google.com/"; }, 500);
}
}
}
我认为您需要使用带有协议的完整URL:
window.open('http://www.google.com');
右键单击问题已在此处得到解答:
右键单击是Javascript事件吗?