Simulating target="_blank" with JavaScript

Had a requirement the other day to simulate target=”_blank” (i.e. opening a webpage in a new window) by just specifying the href attribute. This is done using JavaScript as follows (note that void(0); ensures that nothing is sent back to the page that the link exists on – i.e. the browser doesn’t try to follow the actual href):

<a href=”javascript: window.open(‘http://www.rnowik.com’); void(0);”>This is a test</a>

Note that I have only tested this in IE6.

You May Also Like

About the Author: rnowik

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.