Friendly Popups

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 &quot;name&quot; attribute to the link.

If you want to override the window features of the popup, add a
&quot;windowfeatures&quot; 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;
}

Related posts:

  1. Hibernate Naming Strategies
    Using Hibernate annotations with the default naming strategy leaves you with camelCasedColumnNames in your database schema. Gavin King provided a good camelCase to underscore_separated naming strategy with org.hibernate.cfg.ImprovedNamingStrategy. The only......

This entry was posted in Technical HOWTOs and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Additional comments powered by BackType