iframe 嵌入第三方网站跨域,此图片来自微信公众平台 未经允许不可引用

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)
  }
)
  1. 微信文章图片因防盗链不显示
    在html的head标签中添加
<meta name="referrer" content="never">

添加后如果没效果清除浏览器缓存。第一次加载后资源有缓存,导致浏览器直接读取本地资源,图片还是不能显示,清除缓存刷新就好了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值