Warning: this obviously matters for security! Do this only with code from sources that you absolutely trust.
Here's a basic, simple solution you can build on. This allows you to have an observable whole html structure and populate the iFrame with this data. If you update the HTML, the iframe will update with the new version:
ko.bindingHandlers.iframeContent = { update: function(element, valueAccessor) { var value = ko.unwrap(valueAccessor()); element.contentWindow.document.close();
You can use it as follows:
<p>Edit your html:</p> <textarea data-bind="value: myHtml, valueUpdate: 'afterkeydown'"></textarea> <p>And see it appear in an iframe:</p> <iframe data-bind="iframeContent: myHtml"></iframe>
See this jsfiddle for a demo. valueUpdate simply present, so the demo is more than valueUpdate , it is controversial if it is a good idea in large scripts.
source share