我想在相同的窗口和相同的选项卡中打开一个链接,其中包含有链接的页面。

当我试图打开一个链接使用窗口。打开,然后在新选项卡中打开——而不是在同一窗口的同一选项卡中。


当前回答

   Just Try in button.

   <button onclick="location.reload();location.href='url_name'" 
   id="myButton" class="btn request-callback" >Explore More</button>

   Using href 

  <a href="#" class="know_how" onclick="location.reload();location.href='url_name'">Know More</a> 

其他回答

   Just Try in button.

   <button onclick="location.reload();location.href='url_name'" 
   id="myButton" class="btn request-callback" >Explore More</button>

   Using href 

  <a href="#" class="know_how" onclick="location.reload();location.href='url_name'">Know More</a> 

窗口。Open (url, wndname, params),它有三个参数。如果你不希望它在同一个窗口中打开,只需要设置一个不同的wndname。例如:

window.open(url1, "name1", params); // this open one window or tab
window.open(url1, "name2", params); // though url is same, but it'll open in another window(tab).

下面是关于window.open()的详细信息,你可以信任它! https://developer.mozilla.org/en/DOM/window.open

试试吧~~

你一定要用window.open吗?如果使用window.location="http://example.com"呢?

最突出的javascript特性之一是动态地触发onclick处理程序。我发现以下机制比使用定位更可靠。Href = "或location.reload()或window.open:

// 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
    });

    element.dispatchEvent(evt);
}

// 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;
    fireClickEvent(a);
}

上面的代码也有助于打开新的标签/窗口,绕过所有弹出窗口拦截器!!如。

function openNewTabOrNewWindow(targetURL) {
    var a = document.createElement('a');
    a.href = targetURL;

    a.target = '_blank'; // now it will open new tab/window and bypass any popup blocker!

    fireClickEvent(a);
}

用这个:

location.href = "http://example.com";