多说无益 贴一段使用的代码
getUrl(URL){
//url 为微信公众号文章链接
let http = (window.location.protocol === 'http:' ? 'http:' : 'https:');
let realurl = http + '//cors-anywhere.herokuapp.com/' + URL;
axios.get(realurl).then((response)=>{
console.log(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;
let iframe = document.getElementById('iFrame');
iframe.src = html_src;
},(err)=>{console.log(err);});
总结 1 用ajax请求公众号文章链接 2 js 字符串方法替换 其中 src script http 等字段 3 重新设置 html 头部 4 动态创建 iframe 标签
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有