tec*_*cal 3 html javascript dom
我正在尝试使用HTML5的新离线功能编写Web应用程序.在这个应用程序中,我希望能够编辑一些HTML-一个完整的文档,而不是一个片段<textarea>,按一个按钮,然后<iframe>用找到的HTML 填充一个新的浏览器窗口(或者,还没有决定)在<textarea>.除了本地客户端之外,新内容不会保留在任何位置,因此在window.open呼叫上设置源或在其src上设置属性<iframe>不起作用.
我在StackOverflow上找到了以下问题:" 将HTML从当前页面放到一个新窗口 ",这让我有了一些方法.看起来这种技术适用于片段,但我没有成功地加载一个全新的HTML文档.奇怪的是当我在Firebug中查看DOM时,我看到了新的HTML - 它只是不呈现.
是否可以在新窗口中呈现生成的HTML文档或<iframe>?
编辑:这是一个"工作"的例子,说明我是如何尝试完成此任务的:
<!doctype html>
<html>
<head>
<title>Test new DOM</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
function runonload() {
return $("#newcode")[0].value;
}
$(function() {
$("#runit").click(function() {
w=window.open("");
$(w.document).ready(function() {
$(w.document).html(w.opener.runonload());
});
});
});
</script>
</head>
<body>
<textarea id="newcode">
<!doctype html>
<html>
<head>
<title>New Page Test</title>
</head>
<body>
<h1>Testing 1 2 3</h1>
</body>
</html>
</textarea>
<br/>
<button id="runit">Run it!</button>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我觉得你太复杂了......
试试这个:
<SCRIPT LANGUAGE="JavaScript">
function displayHTML(form) {
var inf = form.htmlArea.value;
win = window.open(", ", 'popup', 'toolbar = no, status = no'); win.document.write("" + inf + ""); } // </script>
<form>
<textarea name="htmlArea" cols=60 rows=12> </textarea> <br> <input type="button" value=" Preview HTML (New Window)" onclick="displayHTML(this.form)"> </form>
Run Code Online (Sandbox Code Playgroud)