1.使用cors-anywhere跨域问题
<iframe id="iFrame" style="width: 100%; height: 100%" frameborder="0" />
getUrl(url) {
const http = window.location.protocol === 'http:' ? 'http:' : 'https:'
// 调用跨域API
let realurl = http + '//cors-anywhere.herokuapp.com/'
axios.get(realurl).then(
(response) => {
let html = response.data
html = html
.replace(/data-src/g, 'src')
.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/g, '')
.replace(/https/g, 'http')
// let html_src = 'data:text/html;charset=utf-8,' + html;
const html_src = html
const iframe = document.getElementById('iFrame')
iframe.src = html_src
var doc = iframe.contentDocument || iframe.document
doc.write(html_src)
doc.getElementById('js_content').style.visibility = 'visible'
},
(err) => {
console.log(err)
}
)
- 微信文章图片因防盗链不显示
在html的head标签中添加
<meta name="referrer" content="never">
添加后如果没效果清除浏览器缓存。第一次加载后资源有缓存,导致浏览器直接读取本地资源,图片还是不能显示,清除缓存刷新就好了。