需求
项目中会有刷新iframe
的需求,
方法
- 一般情况下,我们直接用iframe的
location.reload(true)
方法就可以了,它的缺点是,如果是刷新外部的URL(不同源的),那么这种方法会报跨域的错误。
Blocked a frame with origin xxxx from accessing a cross-origin frame.
- 这个时候我们需要用另外一种方法
window.open()
看例子:
<iframe :src="qrcodePath" name="refresh_name" style="width:300px;height:500px;" id="qrcodeIframe">
<el-button type="primary" @click="refreshIframe" class="refreshBtn">刷新</el-button></iframe>
refreshIframe(){
const iframe = document.getElementById('qrcodeIframe');
window.open(iframe.src,'refresh_name','')
}
网友评论