我在head中写了下面得代码,想劫持alert函数,可是不知道为什么,将这个html打开时,弹出两个框都是内容都是ab,我已经劫持了这个函数,为什么没有效呢?
我在下面定义个button在onclick事件中添加代码alert(“ab”);显示的就是正常的结果,请问这是怎么回事??
<head>
<script language="JavaScript" >
var _alert=alert;
window.alert=function(s){
if(confirm("是否要弹出:"+s)){
_alert(s);
}
}
alert("ab");
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
可能是IE的Bug吧。
楼主是在IE下面测试的吗?我这里火狐表现正常。
好像是,我的IE也不好用,火狐可以,拿到这个ie不支持吗?
这个是用来反劫持的,请问有什么问题吗?我自IE和火狐总做测试了,都不好用O(∩_∩)O~
function unHook(proc){
var f=document.createElement("iframe");
f.style.border="0";
f.style.width="0";
f.style.height="0";
document.body.appendChild(f);
var d =f.contentWindow.document;
d.write("<script type=\"text/javascript\">window.parent.alert=alert;<\/script>");
以下是一段JavsScript脚本,但运行时总会产生 “Microsoft JScript 运行时错误: 'null' 为空或不是对象”异常,大家帮看一下。
<form id="form1" runat="server">
< ......
我想问。。js中可以通过个遍历所有元素并用getelementbyID获取指定ID的元素,那么怎样才能遍历所有元素从而获取有指定class的元素呢??好像没有getelementbyClass这个函数吧??
谢谢!
jquery倒是可以的
$(&quo ......