Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iframe without src but still has content?

While debugging jquery code on their site ( via chrome developer toolbar)

I noticed that their examples are given under Iframe :

Here - for example there is a sample which is under an Iframe but after investigating , I see that the Iframe doesn't have SRC

The picture shows it all

enter image description here

Question :

Is it possible to set content to an Iframe without setting its SRC ?

p.s. this menu also shows me an empty content

enter image description here

like image 695
Royi Namir Avatar asked Aug 04 '13 14:08

Royi Namir


People also ask

Does iframe have to have src?

In order to embed the intended document within the <iframe>, the address of the target document should be specified as src attribute value.

Why iframe is not recommended?

Iframes Bring Security Risks. If you create an iframe, your site becomes vulnerable to cross-site attacks. You may get a submittable malicious web form, phishing your users' personal data. A malicious user can run a plug-in.

Are IFrames being deprecated?

IFrames are not obsolete, but the reasons for using them are rare. Using IFrames to serve your own content creates a "wall" around accessing the content in that area. For crawlers like Google, It's not immediately clear that cotent in an iframe will be ranked as highly as if the content were simply part of the page.

Can you mute an iframe?

An iframe does not have an audio API, so you can't mute anything using JS on that element.


2 Answers

Yes, it is possible to load an empty <iframe> (with no src specified) and later apply content to it using script.

See: http://api.jquery.com/jquery-wp-content/themes/jquery/js/main.js (line 54 and below).

Or simply try:

<iframe></iframe>  <script> document.querySelector('iframe')         .contentDocument.write("<h1>Injected from parent frame</h1>") </script> 
like image 84
haim770 Avatar answered Oct 02 '22 13:10

haim770


Yes, Here is how you change the html of the iframe with jQuery

var context = $('iframe')[0].contentWindow.document,     $body = $('body', context); $body.html('Cool'); 

Demo: http://jsfiddle.net/yBmBa/

document.contentWindow: https://developer.mozilla.org/en-US/d...

like image 21
iConnor Avatar answered Oct 02 '22 11:10

iConnor