Binding string response(with HTMLTags) to iframe

2019-08-31 04:38发布

问题:

I make a ajax call to rest endpoint which returns HTML tags as a string response. Now I need to bind this to iframe.

Here data has html tags like

var data="<html><head><title>iFram</title></head><body>hi</body></html>"

I have tried document.getElementById('iframeid').src=data

also I have tried

$('#iframeid').contents().find("html").append(data);

thanks

回答1:

finally we have got the solution with iframe attribute "srcdoc" which we used like document.getElementById('iframeid').srcdoc=data;