Jump to content

Open a New Window


Recommended Posts

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. thanks

Link to comment
Share on other sites

The simplest technique is to embed an onclick handler in the tag you want to make clickable. Look here: http://www.w3schools.com/jsref/event_onclick.aspIf the embedded code gets long, you might move it into a function in your script, and then the code embedded in your tag would simply call that function.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...