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
3 Answers
Reset to default 4Use 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
评论列表(0条)