hh54188
hh54188

Reputation: 15626

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.

Upvotes: 0

Views: 13449

Answers (4)

Karesh A
Karesh A

Reputation: 1751

Have you tried this?

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

Upvotes: 1

Blaster
Blaster

Reputation: 9110

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

Upvotes: 4

jaypeagi
jaypeagi

Reputation: 3141

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.

Upvotes: 0

Rab
Rab

Reputation: 35572

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

Upvotes: 1

Related Questions