我有一个在对话框而不是主窗口中打开页面的功能。稍微清理过的代码如下:
var baseurl = window.location.origin + '/static/docs/'
function onClickLink(event) {
event.preventDefault();
if ($("#dialog").length == 0) {
setUpDialog()
}
var href = event.target.href;
href = baseurl + href.substring(1 + href.lastIndexOf('/'));
$("#dialog").load(href + ' .body', function(response, status, xhr) {
if (status == "error") {
window.location = event.target.href;
} else {
changeImageSrc();
reStructure();
}
});
$("#dialog").dialog({
modal: true,
title: event.target.text,
width: 960,
position: ['center', 100]
});
}
此代码在 Chrome 中运行良好,但 (status == "error") 在 Firefox 下执行。似乎 Firefox 出现 404 错误,可能是加载页面的图像或类似内容。
关于如何在 Firefox 下也获得 Chrome 行为的任何想法? (你可以找到一个有效的 example here )
最佳答案
在 FireFox 中,window.location.origin 是
undefined
。因此 FireFox 厌倦了获取页面:http://openerp.co.hu/hu/funkcionalis-bemutato/undefined/static/docs/sales.html
失败了
在 chrome 中,window.location.origin
http://openerp.co.hu
。 Chrome 连接以获取页面:http://openerp.co.hu/static/docs/sales.html
并成功
不要依赖 window.location.origin
,请尝试使用:
window.location.protocol + "//" + window.location.host
关于javascript - jQuery.load() 在 Firefox 下响应错误,在 Chrome 下工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5375788/