admin管理员组文章数量:1300110
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 pleted.</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
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 pleted.</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
Share Improve this question edited Feb 17, 2011 at 10:01 Jambobond asked Aug 12, 2009 at 14:06 JambobondJambobond 6193 gold badges12 silver badges23 bronze badges3 Answers
Reset to default 4window.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);
}
}
Like:
var copy = document.getElementById("validationDiv").innerHTML;
Then to create the new window:
var newWin = window.open("", "My window", "width=250,height=250,scrollbars=1,resizable=1")
newWin.document.write("<html><head></head><body>" + copy + "</body></html>")
Something like:
<script>
window.onload = function() {
my_window = window.open ("","mywindow1","status=1,width=350,height=150");
my_window.document.write(document.getElementById('someDiv').innertHTML);
};
</script>
本文标签: htmlJavaScriptwindowonloadput content of a ltdivgtltdivgt onto a new windowStack Overflow
版权声明:本文标题:html - JavaScript - window.onload - put content of a <div><div> onto a new window - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741618371a2388663.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论