I want to convert my HTML string below in an HTML document. The code below works fine on Firefox and Chrome but not in other browsers (Opera, Safari, IE). Can you help me?
var content = '<iframe width="640" height="360" src="//www.youtube.com/embed/ZnuwB35GYMY" frameborder="0" allowfullscreen></iframe>';
var parser = new DOMParser();
var htmlDoc = parser.parseFromString(content,"text/html");
Thank you not to reply in JQuery.
I want to do exactly that, but in javascript
<?php
$content = '<iframe width="640" height="360" src="//www.youtube.com/embed/ZnuwB35GYMY" frameborder="0" allowfullscreen></iframe>';
$doc = new DOMDocument();
$doc->loadHTML($content);
?>
My main goal is to transform my HTML text in an HTML document in order to change the Width and Height properties of my iframe.
On the Tools menu, click Options, and then click the Mail Format tab. Under Message Format, in the Compose in this message format list, click HTML or Plain Text, and then click OK.
To render the html string in react, we can use the dangerouslySetInnerHTML attribute which is a react version of dom innerHTML property. The term dangerously is used here to notify you that it will be vulnerable to cross-site scripting attacks (XSS).
Just call the method html2text with passing the html text and it will return plain text.
Try this
function toNode(iframeString) {
var div = document.createElement('div');
div.innerHTML = iframeString;
iframeNode = div.getElementsByTagName('iframe')[0];
return iframeNode;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With