Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
169
rated 0 times [  176] [ 7]  / answers: 1 / hits: 35563  / 11 Years ago, tue, february 26, 2013, 12:00:00

I want to create a iframe without src ( about:blank ) but that iframe content some javascript html



I need to do it because I don't want create a hosted webpages on server for this mission, this will make more connection to server which are no good for resource. And also don't want to write direct javascript html on webpage because they make the webpage load slow most time when load/running.



How to do it by using javascript (jquery maybe )?



iframe eg :



<iframe src=about:blank width=300 height=250 scrolling=no frameborder=0 marginwidth=0 marginheight=0 ></iframe>


and its content:



<div>xxx</div>
<script type=text/javascript>var abc=1 </script>
<script type=text/javascript src=http://1234.net/js.js></script>


UPDATE



Thanks for some answered following.
But I need to clarify that script will create iframe by javascript also, because the need to create iframes in one page with different ids.
Please look at my test:
http://jsfiddle.net/rDkEw/



The problems are:
if use document.body.appendChild, the iframe will create on body of webpage, but I need it to keep it inside the current div which hold the JavaScript.


More From » iframe

 Answers
25

With jQuery:



$('#myIframe').appendTo('#iframeDiv');


your iframe id = myIframe



your html content div id = iframeDiv;



note: without jQuery, the two other answers seem perfectly suited.


[#80002] Sunday, February 24, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mustafaericho

Total Points: 322
Total Questions: 103
Total Answers: 110

Location: Montenegro
Member since Thu, Jun 16, 2022
2 Years ago
mustafaericho questions
Mon, May 31, 21, 00:00, 3 Years ago
Sun, May 23, 21, 00:00, 3 Years ago
Sat, Feb 13, 21, 00:00, 3 Years ago
Sat, Jan 2, 21, 00:00, 3 Years ago
Thu, Nov 12, 20, 00:00, 4 Years ago
;