通过js提供到iframe的链接 [英] Provide link to iframe via js
本文介绍了通过js提供到iframe的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带src的iframe,但是我想在单击按钮时通过javascript提供到src的链接.如何传递值?
I have an iframe with src but I want to provide the link to src via javascript on click of the button. How do I pass the value?
每次单击按钮时,网页都会刷新.它显示网页,然后刷新以再次显示.如何避免这种情况?
The webpage refreshes everytime I click on the button. It displays the webpage and then refreshes it to display again. How to avoid this?
<button type="button" onclick = "Open()">Click Me!</button>
<iframe id="iframe"
src="" //Provide link here
style="
z-index: 10;
display: None;
">
</iframe>
<script>
function Open() {
let myIframe = document.getElementById("iframe");
myIframe.style.display = 'block';
iframe.src = "www.mylink.com"
}
</script>
推荐答案
在示例中设置src时,您没有引用 myIframe
,您需要执行 myIframe.src ='https://www.mylink.com'
you're not referencing myIframe
when setting src in the example, you need to do myIframe.src = 'https://www.mylink.com'
这篇关于通过js提供到iframe的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文