Reputation: 83745
I need to open certain links in a new window (NOT TAB) with certain dimensions.
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:
$(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>
Upvotes: 5
Views: 20343
Reputation: 1223
if ff is configured to open new windows in tabs you can not open a new window, but instead a tab.
Upvotes: -1
Reputation: 630579
You can pass dimensions to window.open()
for this:
Edited for updated question: notice the [rel|=
changed to [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.
Upvotes: 21
Reputation: 236122
window.open() syntax:
window.open(URI, window name, parameters);
height, width, left, screenX, screenY
, etc. etc.example:
window.open(this.href, "unicorn", "width=400, height=600, screenX=100");
Upvotes: 0
Reputation: 11876
use _blank
example
window.open(this.href, '_blank');
onClick="window.open('http://www.functionx.com/javascript', '_blank');" >
Upvotes: 0
Reputation: 17482
Set the target
attribute to _blank
and don't return false.
$(document).ready(function() {
$('a[rel|=external]').click(function(){
$(this).attr('target', '_blank');
});
});
Upvotes: 0