I have two html documents:
iframe
using an external URL. The URL to that iframe
is created dynamically using jquery .
I want to avoid having two different html documents but rather want to create a new html document dynamically that contains the iframe
, like:
var dynamic_img_path = 'my_external_url';
var html_to_parse = '<html><head><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"><title>my title</title><style type="text/css">html {margin: 0;height: 100%;overflow: hidden;}iframe {position: absolute;left: 0;right: 0;bottom: 0;top: 0;border: 0;}</style></head><body><h1>my heading 1</h1><iframe id="iframe-id" width="100%" height="100%" frameborder="0" src='+ url_param +'></iframe></body></html>';
I then parse the string html_to_parse
to a dom :
var parser = new DOMParser();
var new_html = parser.parseFromString(html_to_parse, "text/html");
This results in an html document as I want it.
But how can I display this new html ? IE How can I use this as I would with a standard window.location
change, so that this new html is shown?
将主体的innerHTML
设置为documentElement.innerHTML
如下所示:
window.document.body.innerHTML = new_html.documentElement.innerHTML
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.