Firefox和Chrome的弹出窗口地址栏不一致

Pop up window address bar is not consitent in Firefox and Chrome

本文关键字:窗口 地址栏 不一致 Chrome Firefox      更新时间:2023-09-26

我的代码如下:

<p>Click the button to open an about:blank page in a new browser window that is 200px wide and 100px tall.</p>
<button onclick="popitup2()">Open Window</button>
JavaScript

function popitup2() {
    newwindow2 = window.open('', 'name', 'height=200,width=150');
    var tmp = newwindow2.document;
    tmp.write('<html><head><title>popup</title>');
    tmp.write('<link rel="stylesheet" href="js.css">');
    tmp.write('</head><body><p>this is once again a popup.</p>');
    tmp.write('<p><a href="javascript:alert(self.location.href)">view location</a>.</p>');
    tmp.write('<p><a href="javascript:self.close()">close</a> the popup.</p>');
    tmp.write('</body></html>');
    tmp.close();
}

当我在Firefox中运行这个时:弹出窗口的地址栏像"http://www.w3schools.com/js/tryit_view.asp?x=0.695266304636076"

当我在Chrome中运行相同的:弹出窗口的地址栏像"about:blank"

我的问题是:

为什么它是不同的两个浏览器,即使我使用相同的代码片段?如何使公共地址栏(url)跨所有浏览器弹出窗口?

甚至我的应用程序都有这个问题。我很想知道这个问题的根本原因。有人能解释一下吗?

当你开始从事web开发工作时,你会经常注意到这样的小不一致——重要的是要记住,虽然HTML/CSS/Javascript都有编写的规范和标准,但实现这些标准取决于浏览器制造商,他们经常选择以可能在不同浏览器之间有小(或大)差异的方式来实现这些标准。你会注意到,在一些移动浏览器上,比如iPhone(据我所知,还有新版本的Chrome),地址栏甚至不显示正常页面的完整URL,而只是显示站点的根地址。这是我们作为web开发人员不得不忍受的——如果它不是技术规范的硬性部分,我们就不能总是期望事情始终如一地运行,或者以我们期望的方式运行。