How to open a new window through javascript when a popup is blocked

How to open a new window through javascript when a 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 of the above code works fine until the browser has blocked the popup. I am trying to open a new window through window.open, see the code above. I want the window to open in any case, if there is a pop-up blocker, it should also open. Please, help!

+4
source share
5 answers

Pop-ups created by window.open can be blocked by pop-up blockers. You can add a new div layer that acts as a popup to solve this problem.

Javascript Modal Dialog

Some problems with popups div

. Drop-down lists are suitable for these pop-ups.

. when resizing the window, the position must be changed

etc.

The page above has resolved many of the tooltip issues.

+7
source

Pop-up blockers only block unintentional pop-ups.

If a pop-up window is displayed while processing a click event from a user, your pop-up window may not be blocked by the pop-up blocker.

So, while the user clicks on a button or link to open a pop-up window, everything will be fine with the current pop-up blockers.

+7
source

The easiest way is to bind it to a button click. No added code is required, and it is designed to prevent people from doing shady things (for example, pop-ups at close range or a huge number of pop-ups).

jQuery, as already mentioned, can get you a β€œpop-up” or modal dialog box, but it will not be very good to open a β€œnew window” at the request of the OP.

+2
source

Code for 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> 
+1
source

try it,

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

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

0
source

Source: https://habr.com/ru/post/1286747/


All Articles