下面应该与您的示例代码一起使用,认为您正在寻找 target="_blank",而不是 _self,因为 _self 是同一个窗口,并且具有完全没有目标值的相同效果。也不要认为 target="_blank" 现在很受鼓励,加上标签浏览器它只会在新标签中打开而不能重新调整大小。
希望以下内容有所帮助
<form target="popup" action="google.com" onsubmit="window.open('', this.target, 'width=300,height=300,resizable,scrollbars=yes'); return true;">
<input type="submit" value="click here"/>
</form>
基于尝试居中弹出窗口的新示例代码。
我认为这个问题令人困惑,因为它不清楚弹出窗口是否正在访问服务器端的内容以及它是否需要访问表单内容。根据您的情况,为这个问题提供的其他答案也可能适合您。下面是我修改后的代码,希望它会有所帮助,但不是 100% 肯定,因为上下文有点混乱
<script>
function openWindow(h, w, url) {
leftOffset = (screen.width/2) - w/2;
topOffset = (screen.height/2) - h/2;
window.open(url, this.target, 'left=' + leftOffset + ',top=' + topOffset + ',width=' + w + ',height=' + h + ',resizable,scrollbars=yes');
}
</script>
<form name="form2" id="form2" method="post" action="google.com" onsubmit="openWindow(300, 300, 'google.com');">
<input type="submit" value="click here"/>
</form>