EDIT:
我了解到,使用_blank
以外的值在移动浏览器上无法打开新的窗口/选项卡.
For example, if you need to open a new window/tab:
This works在所有浏览器上,甚至在移动浏览器上:
target="_blank"
.在移动浏览器上是This does not work,但在桌面浏览器上是does work:
target="new"
--
Although I have this one working, I'm not sure if there's a better way to do it, or if the way I got it is the right/only way.
Basically what I'm doing is replacing all the target="_new"
or target="_blank"
attribute values to target="nw"
, this way only one new window is open and in it all other new windows will open in order to not overwhelm the user with multiple windows.
我还添加了一个"Opens in a new window"title=""
属性.
So the solution I created is this one:
$("a[target='_blank'], a[target='_new']").attr('target','nw').attr('title','Opens in a new window');
注意这两种方法.
Is this the correct way to add two attributes to an element?
我试了.attr('target','nw','title','Opens in a new window')
次,但不起作用.
我问这个问题的原因是因为DYR(不要重复你自己)原则,所以如果我能改进我的代码,很好,如果不能,那就是它.
谢谢