I’ve struggled with popups for some time now. I’ve never really found a good way to handle popping up a new window when clicking a link. Sure, there is the target=”_blank” method but I’ve heard that in XHTML1.0 that is not actually valid. That tells me that browsers can still handle this but might not sometime in the future (or it might end up being included in some kind of quirks rendering mode in the future). A standard Javascript popup is another option but is too easily disabled.
This method will actually do both by creating an event handler.
To make this work you will need the following files:
Then you will need the following code in your header:
<script type="text/javascript" src="#request.urlRoot##request.urlPath#scripts/add-event.js"></script>
<script type="text/javascript">var PATH_TO_POPUP = "/store/media/css/";</script>
<script type="text/javascript" src="#request.urlRoot##request.urlPath#scripts/popup.js"></script>
The PATH_TO_POPUP variable only defines where the .gif image is stored.
To implement this you simply need a normal link:
<a href="http://www.google.com">Google</a>
Add a rel attribute to this to in order to define the popup. You need to pass a space separated list of attributes for the popup in this order: “popup” type width height noicon.
“popup” is always first. This is what actually makes the link a popup link. Type is the type of popup, “standard”, “fullscreen”, or “console”. Width and height are just integer values and noicon is optional. If it is passed in, the pop-up.gif image will NOT be displayed next to the link. Here’s what the link will look like when you are done:
<a href="http://www.google.com" rel="popup standard 800 600 noicon">Google</a>
The great thing about this is that if the user has javascript disabled, the link will still work without any errors, it will just not open a new window.
Thanks to http://www.accessify.com/features/tutorials/the-perfect-popup/ for this method. The only thing that I really changed is I added the PATH_TO_POPUP variable for the ability to move that image around and I created a new type of popup called “console_scroll” which adds scrolling to the console type.


Related Articles
2 users responded in this post
That was a lot of code for such a simple thing
Here’s a smaller, usable, accessible and CSS/HTML/JS compliant method:
function externalLinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName(“a”);
for (var i=0; i<anchors.length; i++) {
var anchor = anchors[i];
if (anchor.getAttribute(“href”) &&
anchor.getAttribute(“rel”) == “external”)
anchor.target = “_blank”;
}
}
window.onload = externalLinks;
All you do is add rel=”external” to all your links (the image to the right of the link you fix via CSS, not JS). Best is to load this little piece of script at the end of the pageload.
Greetings from the Netherlands
Your code will work as well. However, it provides for far fewer options and technically the “target” attribute is not a valid attribute in strict typing HTML or xHTML. See this site: http://www.w3.org/MarkUp/2004/xhtml-faq#target
Leave A Reply