简体   繁体   中英

How to open a new window in the same page

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.

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
})

window.location =newurl; will open a new window replacing the parent

Have you tried this?

<script type="text/javascript">
  window.open ('test.htm','_self',false)
</script>

If you mean you want to replace the current page, window.location = newLocation; will do. If you want a modal popup, try JQuery UI Dialog.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM