2014-01-30 78 views
0

我有这个脚本,将打开弹出时,单击任何机构。 如何改变身体点击它应该是按钮点击或链接点击弹出之前出现?我需要创建任何按钮吗?代码非常感谢。更改主体onclick到按钮onclick

<script type="text/javascript"> 
var win = window.open('http://google.com', "popup", 'toolbars=0, scrollbars=1, location=0, statusbars=0, menubars=0, resizable=1, width=650, height=650, left = 300, top = 50'); 
if (!win){ 
// alert("failed for most browsers"); 
    document.body.onclick = function() { 
     window.open('http://google.com', 'poppage', 'toolbars=0, scrollbars=1, location=0, statusbars=0, menubars=0, resizable=1, width=650, height=650, left = 300, top = 50'); 
    }; 
}else { 
    var thisdoc = document; 
    //Is it Chrome? 
    if(/chrome/.test(navigator.userAgent.toLowerCase())){ 
     setTimeout(function() { 
      if ((win.innerHeight > 0) == false){ 
//    alert("failed for chrome"); 
        thisdoc.body.onclick = function() { 
         window.open('http://google.com', 'poppage', 'toolbars=0, scrollbars=1, location=0, statusbars=0, menubars=0, resizable=1, width=650, height=650, left = 300, top = 50'); 
        }; 
      } 
     }, 100); 
    }else{ 
     win.onload = function() { 
      if ((win.innerHeight > 0) == false){ 
//    alert("failed for others"); 
        thisdoc.body.onclick = function() { 
        window.open('http://google.com', 'poppage', 'toolbars=0, scrollbars=1, location=0, statusbars=0, menubars=0, resizable=1, width=650, height=650, left = 300, top = 50'); 
        }; 
      } 
     }; 
    } 
} 
</script> 

JS:FIDDLE:http://jsfiddle.net/ayiem999/678Ru/(按扭CREATE请播放。)

我回答这个问题,以供参考:

<button id="3" onclick="reply_click(this.id)">B3</button> 

<script type="text/javascript"> 
function reply_click(clicked_id) 
{ 
window.open('http://google.com', 'poppage', 'toolbars=0, scrollbars=1, location=0, statusbars=0, menubars=0, resizable=1, width=650, height=650, left = 300, top = 50'); 
} 
</script> 
+0

你问它是否能够处理按钮点击没有按钮? – SLaks

+0

现在,当我点击任何页面的弹出窗口将出现..我不想那样。我想它应该是一个按钮点击或链接点击不页身体点击 – airi

+0

把'.onclick = function(){}'放在一个按钮元素而不是body上。 –

回答

0

如果您链接或按钮具有myButton一个ID,然后在它的

document.getElementById('myButton').onclick = function() { 
    window.open('http://google.com', 'poppage', 'toolbars=0, scrollbars=1, location=0, statusbars=0, menubars=0, resizable=1, width=650, height=650, left = 300, top = 50'); 
}; 

这是没有的jQuery,因为不需要它。如果你想用它代替那么它的

$('#myButton').on('click', function(){ 
    window.open('http://google.com', 'poppage', 'toolbars=0, scrollbars=1, location=0, statusbars=0, menubars=0, resizable=1, width=650, height=650, left = 300, top = 50'); 
}); 

Demo

+0

我尝试两个,但不知道如何..把小提琴测试..我的网站:http:// bagilaaa .blogspot.com/ – airi

+0

这是小提琴。 http://jsfiddle.net/Pfj8B/ –

+0

是的,我注意到这项工作..你可以检查我的网站为什么它不这样做:http://bagilaaa.blogspot.com/ – airi

0

假设你在你的网页就像有一个按钮

<button id="myButton">My Button</button> 

then

document.body.onclick = function() { 

成为

$('#myButton').click(function() { ... }); 
+0

仍然无法正常工作..我已经把小提琴测试.. – airi