NOTE: The sample is not working in the code snippet editor here because the document is not recognized. Try this locally and it'll work with any HTML you insert in the textarea.
I modified your generatePreview2()
function to receive the value of the textarea and open a new window + writing the textarea value to that new window document.
Does this help you?
$(function () {
$(".link-preview").click(generatePreview);
});
function generatePreview2($value) {
var result_window = window.open('#','_blank', 'height=500,width=500');
result_window.document.write($value);
}
function generatePreview() {
$(".textbox-preview").each(function(){
generatePreview2($(this).val());
});
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>Textarea 1</p>
<textarea class="textbox-preview"></textarea>
<p>Textarea 2</p>
<textarea class="textbox-preview"></textarea>
<span class="link-preview">Preview</span>
EDIT: I modified my code sample and added a loop to generatePreview()
. You can add as many textareas with the same class name as you want, each will open its own window on blick of the button. HOWEVER: Most browsers block those windows if there is more then one. So you need to allow e.g. Chrome in the top right of the URL bar to open as many windows as it wants. Keep that in mind.