我正在尝试打开一个子窗口,并使用脚本标记在窗口代码中包含一个函数。我已经按照我认为的基本步骤我看到其他人在这里使用了示例但是当函数加载它时,当我在父窗口上离开函数时单击预览它将处理构建中的文本时,它无法正常工作窗口,然后将更新后的版本附加到表单,现在如果似乎只是出去了。这是代码http://jsbin.com/kotodiju/1/
的jsbin的链接 var emWindow = window.open("", null, "height=400,width=800,status=yes");
emWindow.document.write(
'<!doctype html><title>Emote Builder<\/title>' +
'<style type="text/css">body{background-color: #00214D;color:White;}<\/style>' +
'<form id="emForm">' +
'Emote Build Window:<br>' +
'<textarea name="emoteBuild" id="emoteBuild" rows="6" cols="80"><\/textarea><br>'+
'<button onclick="emoteFunc()">Preview Emote<\/button>'+
'<button>Send Emote<\/button> '+
'<button>Clear Emote<\/button><br>'+
'Emote Preview<br>'+
'<script>function emoteFunc() {' +
'var emPreview = emWindow.document.getElementById(\'emoteBuild\').value;'+
'emPreview = emPreview.replace(/%%(.+?)%%/g, "<span style=\"color:red\">\"$1\"<\/span>");'+
'emPreview = emPreview.replace(/%%/g, "\"");'+
'emPreview = emPreview.replace(/\^/g, "");'+
'emPreview = emPreview.replace(/(\w+_him)/g, "(him/her)");'+
'emPreview = emPreview.replace(/(\w+_his)/g, "(his/her)");'+
'emPreview = emPreview.replace(/(\w+_he)/g, "(he/she)");'+
'emPreview = emPreview.replace(/#/g, "");'+
'var div = emWindow.document.createElement(\'div\');'+
'div.class = "emPreviews";'+
'div.id = "emPreviews";'+
'div.style.color = "black";'+
'div.style.backgroundColor = "white";'+
'div.innerHTML = emPreview;'+
'emForm.appendChild(div);'+
'emForm.appendChild(linebreak);}<\/script>'
);
emWindow.document.close();