How to open hyperlink in new window

We can open hyperlink in new window using javascript.

lets consider you have the following hyperlink

<a class="link" onclick="openWindow();"> open me in new window </a>
As we are not using href attribute above hyperlink is shown as plain text. So use below styles to make it look as a hyperlink

.link {
    colorblue;
    cursorpointer;
}

Now add the following javascript code

function openWindow() {
    window.open('http://coding-issues.com''''width=950,height=700');
}

The above javascript opens the new window when you click on the hyperlink.

Note: You have to specify the height and width of the new window. Otherwise it opens a new tab instead of new window.

Demo:

open me in new window


In this way we can open the hyperlink in new window using javascript.

For more posts on Javascript visit: javascript

No comments:

Post a Comment