Open URL in same window and in same tab

Open URL in same window and in same tab

I want to open a link in the same window and in the same tab that contains the page with the link.
When I try to open a link by using, then it opens in new tab—not in the same tab in the same window.


Solution 1:

You need to use the name attribute:"","_self")

Edit: Url should be prepended with protocol. Without it tries to open relative url. Tested in Chrome 59, Firefox 54 and IE 11.

Solution 2:

Use this:

location.href = "";

Solution 3:

In order to ensure that the link is opened in the same tab, you should use window.location.replace()

See the example below:



Solution 4:

You can have it go to the same page without specifying the url:'?','_self');

Solution 5:

If you have your pages inside “frame” then

will be redirected inside same frame. So by using


we can load the page as new request.

Solution 6:

One of the most prominent javascript features is to fire onclick handlers on the fly. I found following mechanism more reliable than using location.href='' or location.reload() or

// this function can fire onclick handler for any DOM-Element
function fireClickEvent(element) {
    var evt = new window.MouseEvent('click', {
        view: window,
        bubbles: true,
        cancelable: true


// this function will setup a virtual anchor element
// and fire click handler to open new URL in the same room
// it works better than location.href=something or location.reload()
function openNewURLInTheSameWindow(targetURL) {
    var a = document.createElement('a');
    a.href = targetURL;

Above code is also helpful to open new tab/window and bypassing all pop-up blockers!!! E.g.

function openNewTabOrNewWindow(targetURL) {
    var a = document.createElement('a');
    a.href = targetURL; = '_blank'; // now it will open new tab/window and bypass any popup blocker!