Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
454 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 Answer

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中测试过。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...