[英]jQuery open link in new window with small dimensions (NOT TAB)
我需要在具有特定尺寸的新窗口(NOT TAB)中打開某些鏈接。
這將在新標簽中打開一個鏈接:
$(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>
您可以將尺寸傳遞給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;
});
});
你可以在這里測試它 ,尺寸與標簽不同是這里的關鍵。 請記住, 它仍然可以在選項卡中打開 ,有很多瀏覽器選項,擴展和插件專門用於防止彈出窗口。
此外,從用戶的角度來看,太多的彈出窗口會鼓勵我追捕你並用沙拉叉刺傷你的眼睛和/或彈出一個窗口然后把它扔出去,所以請謹慎使用。
將target
屬性設置為_blank
並且不返回false。
$(document).ready(function() {
$('a[rel|=external]').click(function(){
$(this).attr('target', '_blank');
});
});
使用_blank
例
window.open(this.href, '_blank');
onClick="window.open('http://www.functionx.com/javascript', '_blank');" >
window.open()語法:
window.open(URI, window name, parameters);
height, width, left, screenX, screenY
等。 例:
window.open(this.href, "unicorn", "width=400, height=600, screenX=100");
如果ff配置為在選項卡中打開新窗口,則無法打開新窗口,而是打開選項卡。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.