如果点击两次,则在同一个窗口中加载_blank链接 [英] Load _blank link in the same window if clicked twice
问题描述
是否有可能?
所以我有一个链接:
< ; a href ='/ page.htm'target ='_ blank'>
如果他们点击两次,空白标签。有没有办法让这个特定的链接每次都加载到同一个新选项卡中?
您可以分配一个 onclick
处理程序添加到调用窗口对象的 open
方法的锚点。第一次点击锚时,它会打开一个新的浏览标签。
注意的第二个参数打开
方法(即其他窗口)。这是新选项卡的句柄。如果要将新内容加载到该选项卡中(而不是打开另一个选项卡),只需使用与第二个参数相同的句柄再次调用 open
方法:
(function(){
var childWindowOpen = false;
window.onload = function(event){
var anchor = document.getElementById(child-window-link);
anchor.onclick = function(event){
var childWindow;
if(!childWindowOpen){
childWindow = window.open(otherpage.html,other-window);
} else {
childWindow = window.open(yetanotherpage.html,other-window);
}
childWindowOpen = true;
return false;
}
};
}());
Is it possible?
So I have a link:
<a href='/page.htm' target='_blank'>
If they click it twice, it will load up two blank tabs. Is there anyway to get this particular link to load in the same new tab each time?
You can assign an onclick
handler to the anchor that calls the open
method of the window object. The first time the anchor is clicked, it opens a new browsing tab.
Notice the second parameter to the open
method (i.e., "other-window"). This is a handle to the new tab. If you want to load new content into that tab (instead of opening yet another tab), just call the open
method again with that same handle as the second parameter:
(function () {
var childWindowOpen = false;
window.onload = function (event) {
var anchor = document.getElementById("child-window-link");
anchor.onclick = function (event) {
var childWindow;
if (!childWindowOpen) {
childWindow = window.open("otherpage.html", "other-window");
} else {
childWindow = window.open("yetanotherpage.html", "other-window");
}
childWindowOpen = true;
return false;
}
};
}());
这篇关于如果点击两次,则在同一个窗口中加载_blank链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!