在发帖之前,我阅读了与标题相关的帖子,我确信我的问题有解决方案,但我对扩展、JavaScript 和 JQuery 是个菜鸟,我不知道...
导致拒绝的代码是:
innerframe = $("<iframe/>").css({
top: WIDGET_TITLE_HEIGHT + "px",
left: "0px",
width: "100%",
height: "1000px",
border: "none",
align: "center",
display: "block"})
.appendTo(innerdiv)
.load(function() {
onStart()
})
.attr({
frameBorder: 0,
//scrolling:0,
src: 'javascript:(function(){document.open();document.domain="' + document.domain + '";document.write(\' <!DOCTYPE html>' + '\');document.close();})();'
})[0];
行 src: 'javascript....' 是罪犯,但我不知道解决方案是什么。
我读过的帖子清楚地表明代码违反了 Chrome 的 CSP,并且我看到了消息传递、沙盒等的提及。
我希望有人能提供解决方案并帮助我了解发生了什么。
提前致谢!
最佳答案
您的脚本可能违反了 Same origin policy ,它表示脚本只能在来自同一域的页面上执行。具体来说,它们必须具有相同的协议(protocol)和主机。
您的线路document.write(\' <!DOCTYPE html>' + '\');
可能是罪魁祸首。
关于javascript - 拒绝执行 JavaScript URL,因为它违反了以下内容安全策略指令 :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18678527/