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.

Method-1

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

Method-2

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

Tags

Similar posts