Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
383 views
in Technique[技术] by (71.8m points)

javascript - 在同一窗口和同一选项卡中打开URL(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 window.open , then it opens in new tab—not in the same tab in the same window.(当我尝试使用window.open打开链接时,它会在新选项卡中打开 - 而不是在同一窗口的同一选项卡中。)   ask by user1065055 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to use the name attribute:(您需要使用name属性:)

window.open("https://www.youraddress.com","_self") Edit : Url should be prepended with protocol.(编辑 :网址应该附加协议。) Without it tries to open relative url.(没有它试图打开相对网址。) Tested in Chrome 59, Firefox 54 and IE 11.(在Chrome 59,Firefox 54和IE 11中测试过。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...