我这样的代码在同一浏览器中从一个选项卡创建新选项卡到另一个选项卡.
function newTab()
{
var form1 = document.createElement("form");
form1.id = "newTab1"
form1.method = "GET";
form1.action = "domainname"; //My site address
form1.target = "framename"; //Browser tab name
document.body.appendChild(form1);
form1.submit();
}
上面的代码正常工作以创建新选项卡.当点击“MyNewTab”链接主页时
最佳答案
您需要在javascript cookie中设置当前选定的选项卡,并始终在页面加载时读取此cookie并设置选项卡
原文链接:https://www.f2er.com/js/425458.html你可以在newTab()函数中设置cookie:
function newTab()
{
var form1 = document.createElement("form");
form1.id = "newTab1"
form1.method = "GET";
form1.action = "domainname"; //My site address
form1.target = "framename"; //Browser tab name
$.cookie("currentTab","framename");//set the selected tab name in cookie
document.body.appendChild(form1);
form1.submit();
}
然后,在页面加载事件:
var tabName=$.cookie("currentTab")//get the current tab name from cookie.
if(tabName==null){
tabName="default tab name"//at first time the cookie will be null,//so you need to assign a default value if the cookie is null
}
//set this tab as selected