admin管理员组文章数量:1024194
I'm trying to access html document from one of my frames with javascript, but I'm getting a Uncaught DOMException: Blocked a frame with origin "null" from accessing a cross-origin frame.
error.
This is the main page:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script>
(function(window, document, undefined){
window.onload = init;
function init(){
var iframe = document.getElementById('main_frame');
var innerDoc = (iframe.contentDocument) ? iframe.contentDocument : iframe.contentWindow.document;
var ulObj = innerDoc.getElementById("div-content");
console.log(ulObj.innerHTML);
}
})(window, document, undefined);
</script>
</head>
<frameset rows="*" noresize="noresize" border="0" frameborder="no" framespacing="0">
<frame src="frame.html" id="main_frame" frameborder="no" marginheight="0" marginwidth="0">
</frameset>
</html>
And this is the frame:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div id="div-content">
abc
</div>
</body>
</html>
As you can see, I'm trying to extract the div
's content which is: "abc".
I think that both: iframe.contentDocument : iframe.contentWindow.document
are null and I don't know why.
I'm trying to access html document from one of my frames with javascript, but I'm getting a Uncaught DOMException: Blocked a frame with origin "null" from accessing a cross-origin frame.
error.
This is the main page:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script>
(function(window, document, undefined){
window.onload = init;
function init(){
var iframe = document.getElementById('main_frame');
var innerDoc = (iframe.contentDocument) ? iframe.contentDocument : iframe.contentWindow.document;
var ulObj = innerDoc.getElementById("div-content");
console.log(ulObj.innerHTML);
}
})(window, document, undefined);
</script>
</head>
<frameset rows="*" noresize="noresize" border="0" frameborder="no" framespacing="0">
<frame src="frame.html" id="main_frame" frameborder="no" marginheight="0" marginwidth="0">
</frameset>
</html>
And this is the frame:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div id="div-content">
abc
</div>
</body>
</html>
As you can see, I'm trying to extract the div
's content which is: "abc".
I think that both: iframe.contentDocument : iframe.contentWindow.document
are null and I don't know why.
1 Answer
Reset to default 1It looks like if you're trying to access frames directly from your browser without having a web service, you're disallowed due to security reasons (you could access system files).
I solved my issue by installing xampp and moving all my files to htdocs and everything worked as expected.
I'm trying to access html document from one of my frames with javascript, but I'm getting a Uncaught DOMException: Blocked a frame with origin "null" from accessing a cross-origin frame.
error.
This is the main page:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script>
(function(window, document, undefined){
window.onload = init;
function init(){
var iframe = document.getElementById('main_frame');
var innerDoc = (iframe.contentDocument) ? iframe.contentDocument : iframe.contentWindow.document;
var ulObj = innerDoc.getElementById("div-content");
console.log(ulObj.innerHTML);
}
})(window, document, undefined);
</script>
</head>
<frameset rows="*" noresize="noresize" border="0" frameborder="no" framespacing="0">
<frame src="frame.html" id="main_frame" frameborder="no" marginheight="0" marginwidth="0">
</frameset>
</html>
And this is the frame:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div id="div-content">
abc
</div>
</body>
</html>
As you can see, I'm trying to extract the div
's content which is: "abc".
I think that both: iframe.contentDocument : iframe.contentWindow.document
are null and I don't know why.
I'm trying to access html document from one of my frames with javascript, but I'm getting a Uncaught DOMException: Blocked a frame with origin "null" from accessing a cross-origin frame.
error.
This is the main page:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script>
(function(window, document, undefined){
window.onload = init;
function init(){
var iframe = document.getElementById('main_frame');
var innerDoc = (iframe.contentDocument) ? iframe.contentDocument : iframe.contentWindow.document;
var ulObj = innerDoc.getElementById("div-content");
console.log(ulObj.innerHTML);
}
})(window, document, undefined);
</script>
</head>
<frameset rows="*" noresize="noresize" border="0" frameborder="no" framespacing="0">
<frame src="frame.html" id="main_frame" frameborder="no" marginheight="0" marginwidth="0">
</frameset>
</html>
And this is the frame:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div id="div-content">
abc
</div>
</body>
</html>
As you can see, I'm trying to extract the div
's content which is: "abc".
I think that both: iframe.contentDocument : iframe.contentWindow.document
are null and I don't know why.
1 Answer
Reset to default 1It looks like if you're trying to access frames directly from your browser without having a web service, you're disallowed due to security reasons (you could access system files).
I solved my issue by installing xampp and moving all my files to htdocs and everything worked as expected.
本文标签:
版权声明:本文标题:javascript - Unable to get frame content, Uncaught DOMException: Blocked a frame with origin "null" from acces 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745518658a2154210.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论