【发布时间】:2015-03-24 20:09:36
【问题描述】:
我正在使用“fancy box”,我正在尝试将我的网址更改为fancy box 的 url,所以我尝试使用 History.pushState()。
但它会出错
错误:
未捕获的安全错误:无法在“历史”上执行“pushState”:无法在来源为“http://localhost:28587”的文档中创建 URL 为“about:blank”的历史状态对象
我的代码:
var _url = window.location.href;
setInterval(function () {
if (($(".fancybox-iframe").length > 0))
{
if(window.location.href != $('.fancybox-iframe').contents().get(0).location.href)
{
history.pushState(null, null, $('.fancybox-iframe').contents().get(0).location.href);
}
}
else
{
if(window.location.href != _url)
{
history.pushState(null,null, _url);
}
}
}, 80);
我想搜索它,但没有找到答案,请帮助我
或建议我更好的解决方案。
(我发现了这个:Javascript history.PushState not working? 但我不明白我的代码中有什么问题)
编辑:
另一个问题是,当我在浏览器中按“返回”时,url 发生了变化,但没有实际加载,为什么??
【问题讨论】:
-
请有人帮帮我!!
-
记录
$('.fancybox-iframe').contents().get(0).location.href的值并将它们添加到问题中,因为这可能是您的问题的原因 -
它从 iram 中获取 url,如果我打开谷歌,
$('.fancybox-iframe').contents().get(0).location.href将是http://www.google.com。在我的例子中http://localhost:27477/PerPage/content.php?d=1&f=1我用警报检查它。另一个问题是,当我在浏览器中按“返回”时,url 已更改但未实际加载,为什么?@GlenSwift
标签: javascript jquery url fancybox-2 pushstate