How to access iframe checkbox elements

I have a webpage consisting of a checkbox (parent), and on the same webpage I also have an iframe created from another page that displays multiple records that also have a checkbox (children) for each record. If I select the parent checkbox, I would like to set up cascading access to all child checkboxes in the iframe, and also disable these child checkboxes.

How can I access the checkboxes inside the iframe?

My iframe definition on the manual page looks like the following:

<iframe id="iframe1" src="'+URL+'" style="border:none;width:799px;height:200px;" frameborder="1" framespacing="0" marginheight="0" marginwidth="0"></iframe>
+3
source share
4 answers

Ok, here is an example ...

First, this is the source for the iFrame content (I named it FramePage.htm) ...

<body>
    <input id="Checkbox1" type="checkbox"  name="checkbox" /> 
    <input id="Checkbox2" type="checkbox" name="checkbox"/>
    <input id="Checkbox3" type="checkbox" name="checkbox" />
</body>

, iFrame...

<iframe id="frame" src="FramePage.htm"></iframe>

<input id="Button1" type="button" value="button" onclick="setData()" />

<script type="text/javascript">
    function setData()
    {
        var frame = document.getElementById('frame');

        var checkboxes = frame.contentWindow.document.getElementsByName('checkbox');

        for (var i = 0; i < checkboxes.length; i++)
        {
            checkboxes[i].checked = true;
        }
    }
</script>

"" .

, :)

+6

: jquery iframe. , , peter.

+1

URL- iframe src , , , JavaScript .

0

$("#select_checkbox").change(function(event){
    $("#content").contents().find(':checkbox').each(function(){
        jQuery(this).attr('checked', $("#select_checkbox").is(':checked'));
    });
});

select_checkbox ,

0

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


All Articles