JSFiddle - React, Tailwind, and code Playground

HTML

<button>Write!</button>
<iframe id='frame' src='/w94a9arv/show'></iframe>

CSS

iframe {
    width:500px;
    height:200px;
}

JavaScript

function getSelectionHtml(iframeWindow) {
    var iframeWindow = iframeWindow || window;
    var html = "";
    if (typeof iframeWindow.getSelection != "undefined") {
        var sel = iframeWindow.getSelection();
        if (sel.rangeCount) {
            var container = iframeWindow.document.createElement("div");
            for (var i = 0, len = sel.rangeCount; i < len; ++i) {
                container.appendChild(sel.getRangeAt(i).cloneContents());
            }
            html = container.innerHTML;
        }
    } else if (typeof iframeWindow.document.selection != "undefined") {
        if (iframeWindow.document.selection.type == "Text") {
            html = iframeWindow.document.selection.createRange().htmlText;
        }
    }
    return html;
}

$('button').click(function(){
    alert(getSelectionHtml($('iframe').get(0).contentWindow));
});