最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

popup - how to open new window through javascript when pop up is blocked - Stack Overflow

programmeradmin2浏览0评论

How can I open a new window through javascript when popup is blocked in IE and Firefox.

Below is the code:

<%@ Page language="c#" AutoEventWireup="false" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > 

<html>
  <head>
    <title>SessionRedirect</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name=vs_defaultClientScript content="JavaScript">
    <meta name=vs_targetSchema content="">
  </head>
  <body MS_POSITIONING="GridLayout">

    <form method="post" name="frmRedirect">   
        <input type="hidden" name="email" value="<%=Session["Email"].ToString() %>" />
        <input type="hidden" name="pass" value="<%= Session["PWD"].ToString() %>" />
        <input type="hidden" name="User" value="<%= Session["User"].ToString() %>" />
    </form>

<script type="text/javascript"> 

    if(frmRedirect.User.value == "P")
    {
        window.open("", "Partner", "height=650,width=1075,left=100,top=100,status=1,scrollbars=1,location=1,toolbar=1;resizable=1");
        frmRedirect.target="Partner";       
        frmRedirect.action = "/partnerzone/index.aspx";
        document.frmRedirect.submit(); 
        location.replace("index.aspx");
    }
    else
    {
        window.open("", "Student", "height=650,width=1075,left=100,top=100,status=1,scrollbars=1,location=1,toolbar=1;resizable=1");
        frmRedirect.target="Student";
        frmRedirect.action = "/studentzone/index.aspx";
        document.frmRedirect.submit(); 
        location.replace("index.aspx");
    }   

</script>

<%
    Session.Remove("registration");
    Session.Remove("User");
    Session.Remove("UserId");
    Session.Remove("UserLoggedIn");
    Session.Remove("AgentCode");
    Session.Abandon();
%>

  </body>
</html>

all the above code is working fine, until the browser has blocked the popup. I am trying to open new window through window.open, please see the above code. I want the window should open in any case, if there is pop up blocker it should also open. Please help!

How can I open a new window through javascript when popup is blocked in IE and Firefox.

Below is the code:

<%@ Page language="c#" AutoEventWireup="false" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > 

<html>
  <head>
    <title>SessionRedirect</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name=vs_defaultClientScript content="JavaScript">
    <meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
  </head>
  <body MS_POSITIONING="GridLayout">

    <form method="post" name="frmRedirect">   
        <input type="hidden" name="email" value="<%=Session["Email"].ToString() %>" />
        <input type="hidden" name="pass" value="<%= Session["PWD"].ToString() %>" />
        <input type="hidden" name="User" value="<%= Session["User"].ToString() %>" />
    </form>

<script type="text/javascript"> 

    if(frmRedirect.User.value == "P")
    {
        window.open("", "Partner", "height=650,width=1075,left=100,top=100,status=1,scrollbars=1,location=1,toolbar=1;resizable=1");
        frmRedirect.target="Partner";       
        frmRedirect.action = "http://pli.cmsstag/partnerzone/index.aspx";
        document.frmRedirect.submit(); 
        location.replace("index.aspx");
    }
    else
    {
        window.open("", "Student", "height=650,width=1075,left=100,top=100,status=1,scrollbars=1,location=1,toolbar=1;resizable=1");
        frmRedirect.target="Student";
        frmRedirect.action = "http://pli.cmsstag/studentzone/index.aspx";
        document.frmRedirect.submit(); 
        location.replace("index.aspx");
    }   

</script>

<%
    Session.Remove("registration");
    Session.Remove("User");
    Session.Remove("UserId");
    Session.Remove("UserLoggedIn");
    Session.Remove("AgentCode");
    Session.Abandon();
%>

  </body>
</html>

all the above code is working fine, until the browser has blocked the popup. I am trying to open new window through window.open, please see the above code. I want the window should open in any case, if there is pop up blocker it should also open. Please help!

Share Improve this question edited Jun 25, 2009 at 14:09 Manoj Singh asked Jun 25, 2009 at 12:06 Manoj SinghManoj Singh 7,70734 gold badges122 silver badges200 bronze badges 0
Add a comment  | 

5 Answers 5

Reset to default 7

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/

发布评论

评论列表(0)

  1. 暂无评论