问题描述
我有一个按钮:
<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');
})
但总是在新标签或新窗口中打开,我尝试了第二个参数 _self
_top
.我什至尝试过 window.location.href(newurl)
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)
那么我该如何解决这个问题?它与浏览器或操作系统有关吗?我在 Mac OS 的 firefox 和 chrome 中查看.
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.
OP 已经通过他在问题下方的评论消除了所有的困惑,这是您为当前窗口设置新网址所需的:
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
})
这篇关于如何在同一页面打开新窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!