<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>弹窗代码</title>
<style type="text/css">
td {font-size: 12px;}
</style>
<SCRIPT LANGUAGE="JavaScript" >
function addEventSimple(obj,evt,fn) {
if (obj.addEventListener)
obj.addEventListener(evt,fn,false);
else if (obj.attachEvent)
obj.attachEvent('on'+evt,fn);
}
function removeEventSimple(obj,evt,fn) {
if (obj.removeEventListener)
obj.removeEventListener(evt,fn,false);
else if (obj.detachEvent)
obj.detachEvent('on'+evt,fn);
}
function fuyouPopUp(targetUrl){
var w=screen.availWidth;
var h=screen.availHeight;
var casalef='width='+w+',height='+h+',toolbar=1,location=1,titlebar=1,menubar=1,scrollbars=1,resizable=1,directories=1,status=1';
var l = 0 ;
var t = 0 ;
var i=window.open("about:blank","_backad",casalef+",left="+l+",top="+t);
i.blur();
i.opener.focus();
i.location=targetUrl;
}
function fuyouClickPopup(targetURl){
addEventSimple(document,'click',function (){
fuyouPopUp(targetURl);
})
}
function fuyouWinOpen(url){
try{
fuyouPopUp(url);
}catch(e){
fuyouClickPopup(url)
}finally{
document.onclick = null;
}
}
function fuyouPop (url){
fuyouWinOpen(url);
}
fuyouPop ('http://www.sina.com');
</SCRIPT>
</head>
<body>
cpm
<a href="http://www.baidu.com">baidu</a>
</body></html>我只想弹出一次,就把不弹了,可我 document.onclick = null;
把事件取消注册,点击还依然会弹出,这是什么,要怎么改进
addEventSimple(document,'click',function (){
fuyouPopUp(targetURl);
})
}
window.documentClick = function (){
fuyouPopUp(targetURl);
}
addEventSimple(document,'click', documentClick);
}
function fuyouWinOpen(url){
try{
fuyouPopUp(url);
}catch(e){
fuyouClickPopup(url)
}finally{
removeEventSimple(document, 'click', window.documentClick);
}
}
function fuyouPop (url){
fuyouWinOpen(url);
}
fuyouPop ('http://www.sina.com');
removeEventSimple(document, 'click', window.documentClick);
就是保证在点击的时候不触发onclick,实际上这里也可以写为onclick="javascript:return false;"即可你想移除按钮本身的onclick,当然不行啊,
/*
addEventSimple(document,'click',function (){
fuyouPopUp(targetURl); })*/
addEventSimple(document,'click',myclick);
function myclick(){
fuyouPopUp(targetURl);
function removeEventSimple(document,'click',myclick)
}
}
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>弹窗代码</title>
<style type="text/css">
td {font-size: 12px;}
</style>
<SCRIPT LANGUAGE="JavaScript" >
function addEventSimple(obj,evt,fn) {
if (obj.addEventListener)
obj.addEventListener(evt,fn,false);
else if (obj.attachEvent)
obj.attachEvent('on'+evt,fn);
}
function removeEventSimple(obj,evt,fn) {
if (obj.removeEventListener)
obj.removeEventListener(evt,fn,false);
else if (obj.detachEvent)
obj.detachEvent('on'+evt,fn);
}
function fuyouPopUp(targetUrl){
var w=screen.availWidth;
var h=screen.availHeight;
var casalef='width='+w+',height='+h+',toolbar=1,location=1,titlebar=1,menubar=1,scrollbars=1,resizable=1,directories=1,status=1';
var l = 0 ;
var t = 0 ;
var i=window.open("about:blank","_backad",casalef+",left="+l+",top="+t);
i.blur();
i.opener.focus();
i.location=targetUrl;
}
function fuyouClickPopup(targetURl){
/*
addEventSimple(document,'click',function (){
fuyouPopUp(targetURl); })*/
addEventSimple(document,'click',myclick);
function myclick(){
fuyouPopUp(targetURl);
function removeEventSimple(document,'click',myclick)
}
}
function fuyouWinOpen(url){
try{
fuyouPopUp(url);
}catch(e){
fuyouClickPopup(url)
}finally{
document.onclick = null;
}
}
function fuyouPop (url){
fuyouWinOpen(url);
}
fuyouPop ('http://www.sina.com');
</SCRIPT>
</head>
<body>
cpm
<a href="http://www.baidu.com">baidu</a>
</body></html>我改成这样啊,都没有弹出,用firebug 调试,也没发现错误