Display warning window inside iframe on html page

There is a simple HTML page called say abc.html. Abc.html now has a button called say 'click me'. This page, abc.html, also has an iframe with the identifier "myframe".

Now what I want is that when I click the "click me" button, a warning window appears that should appear inside the iframe with the name "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 this does not work and what might be an alternative solution.

+2
source share
4 answers

ContentWindow , .

, iframe, document.getElementById('targetFrame').contentWindow.targetFunction(); ( targetFunction ). .

+2

<iframe> , , , , .

" " , , , .

+1

alert . , , /, .

JSFiddle

If you need this functionality, you will have to use your own modal dialogs or the library that will present them.

+1
source

This may help you:

function body_load()
{       
    document.getElementById('loader').src;
}
<div id='mydiv'>
    <input type="button" value="Click Me" onclick="body_load();" />
</div>
<iframe id='loader' onload="body_load(this)" name="Google"  scrolling="auto" style="width:95%;height:600px" src="http://www.image.com"></iframe>

http://jsbin.com/idazul/1/edit

0
source

Source: https://habr.com/ru/post/1568108/


All Articles