我想在外部网站上搜索一个简单的字符串,比如<div class="sender" style="display: block;"> in iframe。
代码不起作用
var target = '<div class="sender" style="display: block;">'
console.log( $( "iframe" ).contents().find('body').html().search( target ) != -1 )因为我有个错误
Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "http://website1.com" from accessing a frame with origin "http://website2.com". Protocols, domains, and ports must match.我能做什么呢?
发布于 2016-02-15 16:44:24
看,上面写着Failed to read the 'contentDocument'。
由于安全规则,你不能获得(阅读)任何外部网站有一个不同的领域,你也不能编辑它。
上面写着Protocols, domains, and ports must match.。
发布于 2016-02-15 16:46:18
我建议使用<object></object>或<embed></embed>,或者更好的解决方案是,如果您能够访问正在访问的服务器页面,则在将其发送到客户端时,要在标题中启用跨站点脚本。问题是这个协议、域和端口必须与匹配,加载这个html的唯一方法是让服务器发送适当的标头,同时也要查看这个how to block website from loading in iframe?。
https://stackoverflow.com/questions/35414368
复制相似问题