2009-06-25 60 views
4

如何在彈出窗口在IE和Firefox中被阻止時通過javascript打開新窗口。如何在彈出被阻止時通過javascript打開新窗口

下面是代碼:

<%@ 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> 

所有上面的代碼工作正常,直到瀏覽器已阻止彈出。我試圖通過window.open打開新窗口,請參閱上面的代碼。我希望窗戶在任何情況下都能打開,如果有彈出窗口阻擋器,它也應該打開。 請幫忙!

回答

7

由window.open創建的彈出窗口可以被彈出窗口攔截器阻止。你可以添加一個新的div層,就像彈出來解決這個問題。

Javascript Modal Dialog

一些與DIV彈出窗口的問題是

。下拉列表來自這些彈出窗口的方式。

。在窗口調整位置必須改變

在上面的頁面中有許多與一個div彈出的問題已經得到解決。

+0

謝謝,我可以有上述問題的代碼。 – 2009-06-25 12:13:52

+3

@Manoj - 如果你不反對框架,你可以使用jQuery UI對話框小部件。 – tvanfosson 2009-06-25 12:25:50

1

代碼股利理念:

<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> 
7

彈出廣告攔截唯一阻止意外的彈出窗口。

如果在處理用戶的點擊事件時顯示彈出窗口,則彈出窗口阻止程序可能不會阻止彈出窗口。

所以只要你的用戶點擊一個按鈕或一個鏈接來打開彈出窗口,它將與當前彈出窗口阻止程序確定。

2

最簡單的方法是將其綁定到按鈕單擊。不需要額外的代碼,它的目的是防止人們做出陰暗的事情(比如關閉彈窗或大量彈出窗口)。

如上所述,jQuery可以爲您提供'popup'或模式對話框,但不能很好地按照OP要求打開'新窗口'。

相關問題