There is any way to create new iframe in document and put into it full page from variable? I have source code of new page as string in var (including doctype, head section etc.). I can use jQuery for this task.
Asked
Active
Viewed 190 times
1 Answers
0
To generate a new element and append to another use this link (see the accepted answer).
To put the content into the generated iframe element using $("#yourIdOfgeneratedIframe").html(theNameOfYourVariable)
-
It doesn't work. Makes empty iframe with empty body and head section. – user1506098 Jul 06 '12 at 08:36
-
At today evening I try to going a different way. I got a another idea but it is much work to do that. Note: I don't know if it will be successful. – Reporter Jul 06 '12 at 11:23
-
I've tried with something like this: iframe.contents().find('head').html(String(res.match(/\.*[\s\S]*\<\/head\>/m))); iframe.contents().find('body').html((String(res.match(/\.*[\s\S]*\<\/body\>/m)))); It works fine but this method has problems with js scripts including. – user1506098 Jul 06 '12 at 11:48
-
That's was the way I wanted to try. The iframe is a special implementation so you will lose some features of the normal page. Problems with script including can be one effect. Btw. Why don't you use your html code as normaly page? Then you can use the src attribute to load and execute your page. – Reporter Jul 06 '12 at 12:07
-
Because I'm getting this code dynamically. I'm sending form via ajax and I'm getting string in response. (different depending on form data) – user1506098 Jul 06 '12 at 12:32
-
What happens if you use a div as parent element instead of iframe? – Reporter Jul 06 '12 at 12:37