简体   繁体   中英

Show new, dynamically parsed HTML document jQuery

I have two documents:

  • For the main content.
  • One that contains an iframe using an external URL.

The URL to that iframe is created dynamically using .

I want to avoid having two different documents but rather want to create a new 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 :

var parser = new DOMParser();
var new_html = parser.parseFromString(html_to_parse, "text/html");

This results in an document as I want it.

But how can I display this new ? IE How can I use this as I would with a standard window.location change, so that this new 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM