代码之家  ›  专栏  ›  技术社区  ›  Richard Knop

jQuery在新窗口中打开小尺寸链接(不是TAB)

  •  4
  • Richard Knop  · 技术社区  · 14 年前

    我需要打开一个新的窗口(而不是标签)与某些尺寸某些链接。

    这将在新选项卡中打开一个链接:

    $(document).ready(function() {
        $('a[rel|=external]').click(function(){
            window.open(this.href);
            return false;
        });
    });
    

    编辑:这是我的整个javascript文件:

    $(document).ready(function() {
        $('a[rel=external]').click(function(){
            window.open(this.href);
            return false;
        });
        $('a[rel=external-new-window]').click(function(){
            window.open(this.href, "myWindowName", "width=800, height=600");
            return false;
        });
    });
    

    HTML格式:

    <a href="/clientarea/utils/law/id/2832" rel="external-new-window" class="accessible-link">§5, odsek 2</a>
    
    5 回复  |  直到 14 年前
        1
  •  21
  •   Nick Craver    14 年前

    window.open() 为此:
    已编辑以更新问题 :注意 [rel|= 更改为 [rel=

    $(document).ready(function() {
      $('a[rel|=external]').click(function(){
        window.open(this.href);
        return false;
      });
      $('a[rel=external-new-window]').click(function(){
        window.open(this.href, "myWindowName", "width=800, height=600");
        return false;
      });
    });​
    

    You can test it here ,与选项卡不同的尺寸是这里的关键。记住这一点, ,有很多浏览器选项、扩展和插件专门用来防止弹出窗口。

        2
  •  0
  •   Teja Kantamneni    14 年前

    设置 target 属性为 _blank 不要返回false。

    $(document).ready(function() {
        $('a[rel|=external]').click(function(){
            $(this).attr('target', '_blank');
        });
    });
    
        3
  •  0
  •   Sachin R    14 年前

    使用空白

    window.open(this.href, '_blank');
    onClick="window.open('http://www.functionx.com/javascript', '_blank');" >
    
        4
  •  0
  •   jAndy    14 年前

    window.open()语法:

    window.open(URI, window name, parameters);
    
    • URI:作为字符串的位置
    • 参数: height, width, left, screenX, screenY 等等等等。

    window.open(this.href, "unicorn", "width=400, height=600, screenX=100");
    
        5
  •  -1
  •   ipopa    14 年前

    如果ff配置为在选项卡中打开新窗口,则不能打开新窗口,而是打开选项卡。