2014-01-30 77 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