how to open new window through javascript when pop up is blocked

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 22:46:58

Pop ups created by window.open can get blocked by pop up blockers. You can add a new div layer that acts like a pop up to solve this.

Javascript Modal Dialog

Some of the problems with div pop ups are

. dropdown lists come in the way of these pop ups.

. on window resize the position has to be changed

etc

In the above page many of the issues with a div pop up has been solved.

Popup blockers only block unintended popups.

If your popup is displayed while handling a click event from the user, your popup might not be blocked by the popup blocker.

So as long as your user clicks on a button or a link to open the popup, it will be ok with current popup blockers.

The easiest way is to tie it to a button click. No added code required, and it's designed to prevent people from doing shady things (like popups on close, or huge numbers of popups).

jQuery, as mentioned, could get you a 'popup' or a modal dialog, but would not serve very well to open a 'new window' as the OP requested.

Code for the div idea:

<div style="display:none; position: absolute;z-index:99" id="display">you div info here</div>


<script langauge="javascript">

function showPopup ()
{
  var div = document.getElementById("display");

  div.style.display = "inline";

  div.style.top = 20;
  div.style.left = 233;


}

</script>

try this,

$('#myButton').click(function () {
    var redirectWindow = window.open('http://google.com', '_blank');
    redirectWindow.location;
});

Js Fiddle for this http://jsfiddle.net/safeeronline/70kdacL4/2/

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!