iframe跳转到嵌入的html锚点

<iframe id="tempHtml" name="myframe" style="width:100%;height:100%;"  :src="frameUrl+ '#toolbar=0'" frameborder="0" scrolling="auto" ></iframe>
watch: {
anchor: {
deep: true,
immediate:true,
handler (newValue, oldValue) {
console.log('监听新值',newValue,'|||||||||||||||',oldValue)

this.$nextTick(()=>{
this.tempList = [...document.getElementById('tempHtml').contentWindow.document.querySelectorAll('a[href]')]
console.log(newValue,'监听锚点',this.tempList)
this.tempList.map((item) => {
if (item.hash == newValue) {
item.click()
} else {

}
})
})




}
}
},
posted @ 2023-02-10 14:06  士广  阅读(105)  评论(0)    收藏  举报