Jump to content
abdu

Please help me on; Error: iframe is not defined at...

Recommended Posts

I tried to insert an element into iframe so first I must retrieve it by

var frm = document.querySelectorAll(iframe)

but cannot work.

Quote

ReferenceError: iframe is not defined at Object.callback...

How to succeed to insertion as easily as other ordinary elements? thank so much.

Edited by abdu

Share this post


Link to post
Share on other sites

You have to pass a string, which is delimited by either single quotes or double quotes.

var frm = document.querySelectorAll("iframe");

If all you're looking for is a list of iframe elements, you don't need the querySelectorAll method, getElementsByTagName will work just as well.

var frm = document.getElementsByTagName("iframe");

 

Share this post


Link to post
Share on other sites

still not work;

var frm = document.getElementsByTagName("iframe");
console.log('number of  frame= '+ frm.length);

On Chrome Devtool,

Quote

number of  frame= 0

 

 

Share this post


Link to post
Share on other sites

That means that there are no iframes in your document. The might be because you're running the code before the iframes have loaded. Try putting this Javascript at the bottom of your HTML document after everything has finished loading.

Share this post


Link to post
Share on other sites

Or, if you use jQuery you can wrap your code in the $(document).ready() { ... }; function.  In this way, the Javascript will not be run until the full document has been loaded.

Roddy

Share this post


Link to post
Share on other sites

It's possible to do that without having to load the entire jQuery library.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...