右键单击时重定向Javascript
Javascript redirect when right clicking
当一个人右键单击时,你如何使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事件吗?
相关文章:
- 通过javascript重定向html传递php变量
- 使用CSS和Javascript重定向-手持设备
- Javascript重定向循环直到成功
- 如何在通过Javascript重定向时保持StatefulSnippet var值
- JavaScript重定向功能
- Chrome:刷新页面后未呈现的背景图像 + JavaScript 重定向
- 从帖子返回后,Javascript重定向不起作用
- 如果 URL 包含使用 JavaScript 重定向的特定端口
- 由 URL 触发的来自 iFrame 的 JavaScript 重定向
- 模拟隐藏表单提交&使用JavaScript重定向以实现安全支付
- 使用Javascript重定向并设置请求属性
- 谷歌分析调用然后用javascript重定向
- 使用Javascript重定向所有推荐链接
- 在没有flash的情况下使用javascript重定向
- 是否可以在node.js中遵循Javascript重定向
- 带有SetTimout的Javascript重定向不工作
- Rgd:Javascript重定向顶部父页
- JavaScript重定向何时真正生效
- 模态中的JavaScript重定向
- 如何阻止javascript重定向页面