admin管理员组

文章数量:1304100

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.

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.

Share Improve this question edited Feb 20, 2014 at 23:04 tshepang 12.5k25 gold badges97 silver badges139 bronze badges asked Jun 28, 2012 at 10:54 hh54188hh54188 15.7k35 gold badges116 silver badges191 bronze badges 3
  • What you ask is impossible. "New window" is mutually exclusive with "same page." It sounds like you really just want to change the URL in the current window/tab. – Matt Ball Commented Jun 28, 2012 at 10:55
  • Do you wish to open the url in the current window? I am not sure whether or not I understand your question right. – EricG Commented Jun 28, 2012 at 10:56
  • 1 @EricG: Yes, you understand is right – hh54188 Commented Jun 28, 2012 at 10:58
Add a ment  | 

4 Answers 4

Reset to default 4

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 ment 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.

本文标签: javascriptHow to open a new window in the same pageStack Overflow