在从Iframe获取调用的页面高度时,我遇到了一个非常奇怪的错误。我浏览了谷歌,还查看了其他与"访问属性文档的权限被拒绝"相关的Stackoverflow帖子,但还没有找到任何解决方案。我有一个指向另一个服务器的网站。我在Iframe上得到了这个错误。让我提供代码
Jquery
$(document).ready(function()
{
// Set specific variable to represent all iframe tags.
var iFrames = document.getElementsByTagName('iframe');
// Resize heights.
function iResize()
{
// Iterate through all iframes in the page.
for (var i = 0, j = iFrames.length; i < j; i++)
{
// Set inline style to equal the body height of the iframed content.
iFrames[i].style.height = iFrames[i].contentWindow.document.body.offsetHeight + 'px';
}
}
// Check if browser is Safari or Opera.
if ($.browser.safari || $.browser.opera)
{
// Start timer when loaded.
$('iframe').load(function()
{
setTimeout(iResize, 0);
}
);
// Safari and Opera need a kick-start.
for (var i = 0, j = iFrames.length; i < j; i++)
{
var iSource = iFrames[i].src;
iFrames[i].src = '';
iFrames[i].src = iSource;
}
}
else
{
// For other good browsers.
$('iframe').load(function()
{
// Set inline style to equal the body height of the iframed content.
this.style.height = this.contentWindow.document.body.offsetHeight + 'px';
}
);
}
}
);
和IFrame
<iframe style="margin-bottom: 16px;" src="ourteamnav/first.php" frameborder="0" scrolling="no" width="597" height="240"></iframe>
我得到了"访问属性文档的权限被拒绝"错误,所以高度不是根据其中的文档高度来的。然后我尝试了以下代码
function resizeIframe(ifRef)
{
var ifDoc;
//alert(ifRef);
try
{
ifDoc = ifRef.contentWindow.document.documentElement;
}
catch( e )
{
try
{
ifDoc = ifRef.contentDocument.documentElement;
}
catch( ee ){}
}
var doc = ifRef.height;
//alert(doc);
if(ifDoc)
{
ifRef.height = 1;
ifRef.style.height = ifDoc.scrollHeight+'px';
}
}
和Iframe
<iframe onload="resizeIframe(this)" style="margin-bottom: 16px;" src="ourteamnav/first.php" frameborder="0" scrolling="no" width="597" height="240"></iframe`>
在这种情况下,我在javascript上没有发现任何错误,但它不起作用。但奇怪的是,他们两个都在我的本地服务器上工作,而且当代码所在的服务器没有指向另一个服务器时,他们也在工作。(跨站点脚本)。
请帮我解决这个问题。
我使用的参考资料
错误:访问属性';的权限被拒绝;文档';
javascript 中未定义错误文档表单
http://davidwalsh.name/iframe-permission-denied
https://sqa.stackexchange.com/questions/1453/how-to-fix-permission-denied-to-access-property-document
http://sahi.co.in/forums/discussion/2898/error-permission-denied-to-access-property-document-with-ckeditor/p1
http://www.codingforums.com/showthread.php?t=236484
这被称为XSS异常。错误:错误:访问属性"document"的权限被拒绝
不幸的是,您想要做的事情——在不同于父级域的网站上操作iframe的内容或窗口——是不允许的。时期