i want to achieve some feature like this:
var el = document.createElement("iframe");
el.setAttribute('id', 'ifrm');
document.body.appendChild(el);
el.setAttribute('src', 'http://www.example.com');
and if “ifrm” exists, jt won’t create new iframe. if it doesn’t exist, it will create that frame. i want to do this to avoid duplicate frame creation when user keeps click on the same button to generate frame. is there a way to check whether a specific iframe exists? thanks
You can check with getElementById(‘ifrm’) whether or not the frame with that id already exists. If not, create it. Like so:
If you wish to check if there is any iframe at all, you could use getElementsByTagName(‘iframe’).
To make live a little easier, you can take a look at jQuery. This is a Javascript library that helps you to create DOM objects and/or find them in the DOM tree.