JS新人,关于内置事件函数解决方法
JS新人,关于内置事件函数
为什么点击网页却打不开新的窗口?
------解决方案--------------------
可能是被浏览器拦截了,经测试代码没问题。
------解决方案--------------------
chrome版本 29.0.1547.0,测试正常,能弹出窗口。
IE9下异常,打不开,发现文档模式为杂项。添加DOCType,IE9测试正常。
<html>
<head>
<title>Test4</title>
</head>
<body>
<a href="http://www.itcast.cn" class ="itcast" >传智播客1</a>
<a href="http://www.itcast.cn" class ="itcast" >传智播客2</a>
<a href="http://www.itcast.cn" class ="itcast" >传智播客3</a>
<a href="http://www.itcast.cn" class ="itcast" >传智播客4</a>
<script type="text/javascript" src="Test4.js"></script>
</body>
</html>
window.onload = prepareLinks;
function prepareLinks(){
var links = document.getElementsByTagName("a");
for(var i=0;i<links.length;i++){
if(links[i].getAttribute("class")=="itcast"){
links[i].onclick = function(){
popUp(this.getAttribute("href"));
return false;
}
}
}
}
function popUp(winURL){
window.open(winURL,"itcast","width=320,height=480");
}
为什么点击网页却打不开新的窗口?
------解决方案--------------------
可能是被浏览器拦截了,经测试代码没问题。
------解决方案--------------------
chrome版本 29.0.1547.0,测试正常,能弹出窗口。
IE9下异常,打不开,发现文档模式为杂项。添加DOCType,IE9测试正常。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Test4</title>
</head>
<body>
<a href="http://www.itcast.cn" class ="itcast" >传智播客1</a>
<a href="http://www.itcast.cn" class ="itcast" >传智播客2</a>