Home » Java Script » Javascript open the url in new tab

Javascript open the url in new tab

If you’re working with javascript and html sometimes you want to open the url in browser new tab using javascript.Because that process is dynamically doing using javascript and can’t apply the html.For a example If I clicked on the link it open in new tab, but that clicking process is doing by javascript.I think you have an idea about that.OK, let’s see how to open a link in the new tab using javascript.

The normal method as following.But that is not open the new tab.It is opening as new window/popup window.

This is the normal script and it is not open the new tab instead of the new window.

NOTE:-In most cases, this should happen directly in the onclick handler for the link to prevent pop-up blockers and the default “new window” behavior.


NOTE: So you could do it this way or by adding an event listener to your DOM object.


Also you can use $(this).attr('target', '_blank'); when clicked on that element.


Similar posts

  • defenceguruindia

    Hi Sumith,

    I am a blogspot user. Note my URL: http://indiafoodnet.blogspot.in/ which I am presently testing.
    In the home page I have aggregated a couple of links, when the user clicks on a particular link the event to take him to an external URL on a new tab. I am currently using the code mentioned below, but it is opening in the native tab itself. Kindly help me to fine tune this code so that a new tab with the external URL will be opened.

    window.location = “http://externallink.com/”;

    Thanking you,

    Also please visit my current blog: http://defenceguruindia.blogspot.in/