JavaScript - window.onload - 将<div> </ div>的内容放到新窗口中

Jam*_*ond 2 html javascript

我想写一个java脚本:

  1. 当页面加载获取<div>标记的内容时
  2. 将内容放在弹出页面上.

脚本的任何想法?

我知道如何导航到元素但不知道如何复制内容.

div的内容将是这样的

        <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>
Run Code Online (Sandbox Code Playgroud)

其中valadation div包含我要复制到新窗口的内容

干杯

and*_*lzo 5

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);
  }
}
Run Code Online (Sandbox Code Playgroud)

--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);
  }
}
Run Code Online (Sandbox Code Playgroud)