代码之家  ›  专栏  ›  技术社区  ›  Sam

如何创建弹出窗口(好的一种)

  •  3
  • Sam  · 技术社区  · 17 年前

    我需要使用一个弹出窗口向用户显示地址栏,以便他们知道这是一个安全登录,而不是欺骗。例如,如果我使用浮动iframe,网站可能会欺骗我的登录窗口并记录用户的登录信息。

    其他详细信息:我的弹出窗口将来自任何域的iframe中的javascript代码。我知道这听起来像是我在做广告。。但实际上我不是。如果有区别,iframe域和弹出域是相同的。

    1更多细节,我希望做“Facebook连接”做的同样的事情。。。如果你没有登录到facebook,他们允许你通过在任何域的网站上显示一个弹出窗口从该域登录到facebook。例如,访问techcrunch.com上的任何文章,使用Facebook Connect发表评论。确保你已注销facebook,你就会明白我在说什么。

    5 回复  |  直到 17 年前
        1
  •  4
  •   Sean    17 年前

    this site.

    从中复制的一些代码:

    <script language="javascript" type="text/javascript">
    <!--
    function popitup(url) {
        newwindow=window.open(url,'name','height=200,width=150');  
        if(!newindow){
            alert('We have detected that you are using popup blocking software...');}
        if (window.focus) {newwindow.focus()}
        return false;
    }
    
    // -->
    </script>
    

    您可以通过以下链接进行链接:

    <a href="popupex.html" onclick="return popitup('popupex.html')">Link to popup</a> 
    
        2
  •  1
  •   netadictos    17 年前

    Sean示例很好,但您仍然可以通过以下方式检测弹出窗口是否被阻止:

    <script language="javascript" type="text/javascript">
    <!--
    function popitup(url) {
    newwindow=window.open(url,'name','height=200,width=150');
    if(!newwindow){
     alert('We have detected that you are using popup blocking software...');}
    
    if (window.focus) {newwindow.focus()}
    return false;
    }
    
    // -->
    </script>
    
        3
  •  0
  •   Megha    15 年前

    如果弹出窗口拦截器在显式用户操作(如链接或按钮单击)上呈现,则它们不会生效。即使您的浏览器配置为阻止弹出窗口,Facebook connect窗口仍会呈现。这是因为用户单击了“连接”按钮。即使当前站点的域与弹出窗口中的站点不同,这也无关紧要。

        4
  •  0
  •   Daniel J Abraham    10 年前

    这是如何创建一个弹出窗口。。

    <!DOCTYPE html>
    <html>
    <body>
    
    <button onclick="openWin()">Open "myWindow"</button>
    <button onclick="closeWin()">Close "myWindow"</button>
    
    <script>
    var myWindow;
    
    function openWin() {
        myWindow = window.open("", "myWindow", "width=200,height=100");
        myWindow.document.write("<p>This is 'myWindow'</p>");
    }
    
    function closeWin() {
        myWindow.close();
    }
    </script>
    
    </body>
    </html>
    
        5
  •  -1
  •   Jon DellOro    17 年前

    推荐文章