html - Javascript open page in same tab (firefox)? - Stack Overflow

I've been trying to get this right but any of the code i try works.. i looked here and i couldn�

I've been trying to get this right but any of the code i try works.. i looked here and i couldn't find an useful answer. I have this code on the "onclick" event of a button:

function myFunction(){
 window.open("mypage.html","_self");
}

that is supposed to open the url in the same tab, but it doesn't do anything. On the other hand if i take out the "_self" argument, it does work but it opens the url in another tab which is exactly what i don't want.

help please?..

I've been trying to get this right but any of the code i try works.. i looked here and i couldn't find an useful answer. I have this code on the "onclick" event of a button:

function myFunction(){
 window.open("mypage.html","_self");
}

that is supposed to open the url in the same tab, but it doesn't do anything. On the other hand if i take out the "_self" argument, it does work but it opens the url in another tab which is exactly what i don't want.

help please?..

Share Improve this question edited Oct 18, 2011 at 22:55 Slacker616 asked Oct 17, 2011 at 6:24 Slacker616Slacker616 8551 gold badge11 silver badges20 bronze badges 2
  • This should work. Can you point to the actual testcase you're using? – Boris Zbarsky Commented Oct 17, 2011 at 14:55
  • You should not edit your title to say "Solved". You should check the checkmark by the answer that best answered your question. That will indicate to everyone in SO (and to the SO system itself) that your question has been answered and it will count for your own statistics as a question that you asked that was answered. – jfriend00 Commented Oct 17, 2011 at 15:32
Add a ment  | 

3 Answers 3

Reset to default 4

Use this instead:

function myFunction() {
   window.location = "mypage.html";
}

This will replace the current document in the current window/tab with a new document loaded from that URL.

If you want to open in the same tab replacing its contents you could perform a redirect:

window.location.href = 'mypage.html';

you are correct but just to make sure that the target page is in the same location or folder and must be in single quote.

if in the same location/folder then:

window.open('target.html';'_self');

if in different location/folder then:

window.open('folder/target.html';'_self');

Hope this works for you.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744726491a4590211.html

相关推荐

  • html - Javascript open page in same tab (firefox)? - Stack Overflow

    I've been trying to get this right but any of the code i try works.. i looked here and i couldn�

    1天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信