简体   繁体   中英

how to select an iframe tag with javascript?

I m trying to give style to an iframe but it not work

document.getElementsByTagName("iframe").style.resize ="vertical";

I have to give this style to this iframe tag. But when i try this code it gives me error like:

property 'resize' of undefined
    at editPart (c2fd0a58-2ee5-4f88-a11d-c99edf724bbe:443)
    at HTMLTableCellElement.onclick (c2fd0a58-2ee5-4f88-a11d-c99edf724bbe:1)

this is javascript part:

function editPart(url) {

$("#windowEditPart").kendoWindow({
    content: {
        url: url
    }
});
var kendoWindowData = $('#windowEditPart').data('kendoWindow');
kendoWindowData.refresh();
kendoWindowData.center().open();

    window.createTimeout(() => {
         document.getElementsByClassName("k-content")[1].style.resize = "vertical";
    }, 0);
}

here s html part of iframe

<iframe title="Editable area. Press F10 for toolbar." frameborder="0" class="k-content" src='javascript:""'>

</iframe>

getElementsByTagName returns a collection, so you have to select the first item in the returned array:

document.getElementsByTagName("iframe")[0].style.resize = "vertical";

If you know the class you could use

document.getElementsByClassName("k-content")[i].style.resize = "vertical";

where is the index of your iframe in the list of all elements with the class k-content

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM