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:‘’); void(0);”>This is a test</a>

Note that I have only tested this in IE6.

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>