View Full Version : Open a New Window

08-21-2011, 12:21 PM
when a user click on a link, it would open a new window in HTML it is something like this:

<a href="http://google.com" target="_blank">click here</a>

How do I do this in Javascript? So a user would click on the link and it would open a new window. Here's my code

document.writeln('<tr><td>' + "http://google.com" + '</td></tr>');

I know window.open(url) would open a new window, but how do I make it clickable??

Any comments or suggestion would be greatly appreciated.

08-21-2011, 02:06 PM
It really depends on your implementation. What kind of element/object are you trying to make clickable? Any chance we could see some source?

08-21-2011, 02:42 PM
If you're using document.writeln(), you can do:

document.writeln('<tr><td><a href="http://google.com" target="_blank">click here</a></td></tr>');

Or, if
http://google.com is a stand in for a variable assigned earlier:

document.writeln('<tr><td><a href="' + somevariable + '" target="_blank">click here</a></td></tr>');