简体   繁体   English

新窗口中的jQuery打开链接,尺寸小(不是标签)

[英]jQuery open link in new window with small dimensions (NOT TAB)

I need to open certain links in a new window (NOT TAB) with certain dimensions. 我需要在具有特定尺寸的新窗口(NOT TAB)中打开某些链接。

This will open a link in new tab: 这将在新标签中打开一个链接:

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

What to change in order to get links opening in new windows.? 要在新窗口中打开链接需要更改什么。

EDIT: This is my entire javascript file: 编辑:这是我的整个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: HTML:

<a href="/clientarea/utils/law/id/2832" rel="external-new-window" class="accessible-link">§5, odsek 2</a>

You can pass dimensions to window.open() for this: 您可以将尺寸传递给window.open()
Edited for updated question : notice the [rel|= changed to [rel= . 编辑更新的问题 :注意[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 , the dimensions being different from the tab is the key here. 你可以在这里测试它 ,尺寸与标签不同是这里的关键。 Keep this in mind though, it may still open in a tab , there are plenty of browser options, extensions and plugins specifically to prevent popup windows. 请记住, 它仍然可以在选项卡中打开 ,有很多浏览器选项,扩展和插件专门用于防止弹出窗口。

Also, from the user point of view, too many popup windows will encourage me to hunt you down and stab you in the eye with a salad fork and/or pop-up a window and throw you out of it, so please use this sparingly. 此外,从用户的角度来看,太多的弹出窗口会鼓励我追捕你并用沙拉叉刺伤你的眼睛和/或弹出一个窗口然后把它扔出去,所以请谨慎使用。

Set the target attribute to _blank and don't return false. target属性设置为_blank并且不返回false。

$(document).ready(function() {
    $('a[rel|=external]').click(function(){
        $(this).attr('target', '_blank');
    });
});

use _blank 使用_blank

example

window.open(this.href, '_blank');
onClick="window.open('http://www.functionx.com/javascript', '_blank');" >

window.open() syntax: window.open()语法:

window.open(URI, window name, parameters);
  • URI: Location as string URI:位置为字符串
  • window name: A unique identifier, only characters allowed are [AZ,az,0-9,_] 窗口名称:唯一标识符,只允许使用的字符是[AZ,az,0-9,_]
  • parameters: height, width, left, screenX, screenY , etc. etc. 参数: height, width, left, screenX, screenY等。

example: 例:

window.open(this.href, "unicorn", "width=400, height=600, screenX=100");

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM