JavaScript - window.onload - 放入< div>的内容< / div>到一个新的窗口 [英] JavaScript - window.onload - put content of a <div></div> onto a new window
本文介绍了JavaScript - window.onload - 放入< div>的内容< / div>到一个新的窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想编写一个java脚本,其中:
- 当页面加载时,将
< div>
标记和 - 将内容放置在弹出页面上。
脚本的任何想法?
我知道如何导航到元素,但不知道如何复制内容。
div的内容会是这样的
< div id =validationDiv >
< div id =ctl00_Main_OTClaim1_valControlsclass =errorpanelstyle =color:Red;>
< ul>< li>批准人姓名 - 必填字段< / li>< li>每周开始日期 - 必填字段< / li>< li> 。< / li>< li>至少必须声明一个项目才能继续。< / li>< / ul>
< / div>
< / div>
其中valadation div包含我想要复制到新窗口的内容
欢呼
解决方案
window.onload = function(){
var el = document.getElementById(ctl00_Main_OTClaim1_valControls);
var html =;
if(el){
html = document.getElementById(ctl00_Main_OTClaim1_valControls)。innerHTML;
var xopen = window.open(about:blank);
xopen.document.write(html);
}
}
- UPDATE
window.onload = function(){
var el = document.getElementById(ctl00_Main_OTClaim1_valControls); //你想要的元素扩展
var html =;
if(el){
html = el.innerHTML;
var xopen = window.open(about:blank);
xopen.document.write(html);
}
}
I would like to write a java script which:
- When the page loads takes the content of a
<div>
tag and - Places that content on a popup page.
any ideas for the script?
I know how to navigate to the element but have no idea how to copy the content.
The content of the div will be something like this
<div id="validationDiv">
<div id="ctl00_Main_OTClaim1_valControls" class="errorpanel" style="color:Red;">
<ul><li>Approver Name - required field.</li><li>Week Commencing Date - required field.</li><li>Summary of Hours Worked must be completed.</li><li>At least one item must be claimed to proceed.</li></ul>
</div>
</div>
where valadation div contains what i want to copy to the new window
cheers
解决方案
window.onload = function() {
var el = document.getElementById("ctl00_Main_OTClaim1_valControls");
var html = "";
if (el) {
html = document.getElementById("ctl00_Main_OTClaim1_valControls").innerHTML;
var xopen = window.open("about:blank");
xopen.document.write(html);
}
}
--UPDATE
window.onload = function() {
var el = document.getElementById("ctl00_Main_OTClaim1_valControls"); //the element you want expanded
var html = "";
if (el) {
html = el.innerHTML;
var xopen = window.open("about:blank");
xopen.document.write(html);
}
}
这篇关于JavaScript - window.onload - 放入< div>的内容< / div>到一个新的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文