我有这个脚本,当点击任何正文时会打开弹出窗口。 如何改变身体点击它应该是按钮点击或链接点击弹出窗口之前?我需要创建任何东西的按钮。代码非常欣赏。
<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/(按钮创建。请玩)
我对此问题的回答:
<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 :(得分:1)
假设您的页面中有一个按钮,如
<button id="myButton">My Button</button>
然后
document.body.onclick = function () {
成为
$('#myButton').click(function() { ... });
答案 1 :(得分:1)
如果您的链接或按钮的ID为myButton
,那么
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');
});