admin管理员组

文章数量:1300110

I would like to write a java script which:

  1. When the page loads takes the content of a <div> tag and
  2. 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:

  1. When the page loads takes the content of a <div> tag and
  2. 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 badges
Add a ment  | 

3 Answers 3

Reset to default 4
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);
  }
}

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