在html页面的iframe中显示一个警告框 [英] displaying an alert box inside an iframe in an html page
问题描述
有一个简单的HTML页面,名为abc.html。现在abc.html有一个名为say'click me'的按钮。这个页面abc.html也有一个iframe,id为'myframe'。
现在我想要的是当点击按钮'点击我'时,一个警告框应该出现在名为'myframe'的iframe中。我怎样才能做到这一点?
我试过以下内容。
window.frames [ 0] .contentWindow.alert(这是iframe);
但这似乎不起作用。请让我知道为什么这不起作用,什么可能是一个替代解决方案。
ContentWindow是从文档派生的,而不是窗口。你需要做的是在iframe页面上添加一个函数,然后使用 document.getElementById('targetFrame')。contentWindow.targetFunction();
来调用它,(以targetFunction为例)。 此答案可能会为您提供有关技术的更多信息。
There is a simple HTML page, named say abc.html. Now abc.html has a button named say 'click me'. This page, abc.html, also has an iframe, with an id say 'myframe'.
Now what i want is that when the button, 'click me', is clicked an alert box should come up inside the iframe named 'myframe'. How can i do this?
I have tried the following..
window.frames[0].contentWindow.alert("this is the iframe");
but this does not seem to work. Please let me knwo why does this not work and what could be an alternate solution.
ContentWindow is derived from document, not window.
What you will want to do is add the alert into a function on the iframe page, then use document.getElementById('targetFrame').contentWindow.targetFunction();
to call it, (using targetFunction as example). This answer may give you further information on techniques.
这篇关于在html页面的iframe中显示一个警告框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!