views:

789

answers:

3

Hi all,

I would like to write a java script which:

  1. When the page loads takes the content of a 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 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

+2  A: 

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>")
Chris Pebble
.innerHTML dosnt seem to work it returns a null value. :/
Jambobond
ah i have got it, forgot the "marks round validationDiv
Jambobond
+3  A: 

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);
  }
}
andres descalzo
would be a bit more elegant like this: if (el) { html = el.innerHTML;
dalbaeb
yes, I wrote and then amend it with you if (el)
andres descalzo
+2  A: 

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>
karim79