试图阻止我的弹出窗口(需要alt到“window.open”)

时间:2012-06-21 19:05:28

标签: javascript jquery button popup

我正在使用facebook SDK,由于现在的安全问题,它可以通过弹出窗口工作。

所以我有一个处理Facebook [FacebookButton]隐藏的按钮,以及一个测试弹出窗口拦截器[PopupTester]的按钮。

我的代码是这样的,

单击[PopupTester]时,如果弹出窗口有效:关闭它,隐藏此按钮,然后显示[FacebookButton]。

单击[PopupTester]时,如果弹出窗口失败,则显示对话框以促使更改弹出设置,保持[FacebookButton]隐藏,将此按钮值更改为[再试一次]。

function testPopupBlocker() {
  var windowName = 'userConsole'; 
  var popUp = window.open('http://www.whirlocal.com', windowName, 'width=200, height=200, left=24, top=24, scrollbars, resizable');
  if (popUp == null || typeof(popUp)=='undefined') {
    var weGood = "nope";
    alert('Please disable your pop-up blocker and click the link to test again.'); 
  } 
  else {
    var weGood = "yup";
    popUp.close();
  }

}

这很好用,除了这个按钮总是创建一个弹出窗口,但Facebook仍然被阻止了!

除了“window.open”之外还有另一种创建弹出窗口的方法吗?一个更有可能被阻止的人?

编辑:

这是我的按钮代码

<input type="button" class="genButton testPopupButton" name="Test Popup Blocker" title="Test Popup Blocker" value="Test Popup Blocker" onclick="testPopupBlocker()" style="cursor:pointer;" />

<input type="button" class="genButton needsPopups facebookButton" name="AdvocateOnFacebook" title="Recommend <?php echo genesis_get_option('organization','child-settings');?> on Facebook" value="Recommend us on Facebook!" onclick="advocateToFriends()" style="cursor:pointer; display:none;" />

1 个答案:

答案 0 :(得分:0)

您需要使弹出窗口合法化。它需要由用户启动,而不是任意弹出代码,否则弹出窗口阻止程序将阻止它。一旦掌握了弹出窗口,您就可以随意修改它。

试试这个html代码:

<a href="#" onclick="javascript:window.open('http://myurl.com/blank_page.html','userConsole','width=800,height=600,directories=no,location=no,menubar=no,status=no,toolbar=no,scrollbars=auto,resizeable=yes');">
    <div class="some_div_class"><b>Click Me</b></div>
</a>

然后运行testPopupBlocker()函数,看看它是否运行得更好。