Posts tagged quirksmode
Friendly Popups
Jan 20th
If you want a link to open a new window, and can’t use target=”_blank”, you can set javascript to the onclick attribute and make the href go to “#”, but then you can’t ctrl-click the link to open it in a new tab, nor can you see where the link is going in the status bar. Here’s a solution inspired by quirksmode:
<a href="/some/link.html" onClick="return pop(this)">
Here’s the code for pop():
/*
Inspired by http://www.quirksmode.org/js/popup.html
If you want to override the name of the popup window (NOT the title of
the popup), add a "name" attribute to the link.
If you want to override the window features of the popup, add a
"windowfeatures" attribute to the link.
*/
function pop(link) {
var windowfeatures = 'scrollbars=yes,top=100,left=200,height=250,width=450';
if (link.getAttribute('windowfeatures')) windowfeatures = link.getAttribute('windowfeatures');
name = 'pop';
if (link.getAttribute('name')) pop = link.getAttribute('name');
newwindow = window.open(link.href, name, windowfeatures);
if (window.focus) {
newwindow.focus();
}
return false;
}