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

Categories

I have a button:

<button>Click</button>

I want click it and open a new window in the same page, I bind the click event an event handle:

$('button').click(function () {
    var newurl="http://" + window.location["host"] + ";
    window.open(newurl, '_parent');
})

But is always open in new tab or new window, the second parameter I have try _self _top. I even have try window.location.href(newurl)

So how can I solve this problem?Does it matter with browser or OS? I view it in Mac OS's firefox and chrome.

See Question&Answers more detail:os

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

1 Answer

Well that's not possible technically, it also depends on browser tab settings, window settings and third party tab manipulation plugins or addons.


Update

OP has cleared the confusion of all through his comment below his question, this is what you need to set a new url for current window:

$('button').click(function () {
    var newurl="http://" + window.location["host"];
    window.location.href = newurl; // or simply window.location
})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...