vue项目里面有一个iframe组件,想在iframe组件里面加载一个第三方的网站,比如百度,一直报错:由于“X-Frame-Options“指令设为“sameorigin“,已拒绝在框架中载入“https://www.baidu.com/”。
代码如下:
<template> <iframe ref="abc" :style="style" :src="url" frameborder="0"></iframe> </template> <script> @Component({ components: {}, }) export default class DesignerIframe extends Vue { get url() { return "https://www.baidu.com"; } } </script>
最佳解决方案
当第三方网站设置了不允许跨域访问时,就无法通过iframe的方式进行加载。请假在自己的网站, 并且规范设置X-Frame-Options
X-Frame-Options
有三个可能的值:
X-Frame-Options: deny X-Frame-Options: sameorigin X-Frame-Options: allow-from https://example.com/