views:

56

answers:

2

I have a javascript function which get datagrid's header into THEAD tags. This code triggered on body onload event and run correctly.

However, when i look to view source, i can't see these dynamicly generated codes. I want to see it there. How can I do it?

function AddTHEAD(tableName)
{
   var table = document.getElementById(tableName); 
   if(table != null) 
   {
    var head = document.createElement("THEAD");
    head.style.display = "table-header-group";
    head.appendChild(table.rows[0]);
    table.insertBefore(head, table.childNodes[0]); 
   }
}

Edit: I want to talk about why I need this: With the function above, I want Datagrid's header to be shown on every page when I print the page.

For this purpose I have css code below. When I add THEAD tag manually, it works fine. But when it's created by Javascript, it's seen on print preview but not on real printing.

    tHead
   {
    display : table-header-group;
   }

Edit2: I found a clue. When I firstly open print preview page and then click the print button there, it works. But when I directly clik the print button which run window.print javascript code, it don't works. Can anyone has a solution about it?

+7  A: 

You won't be able to see javascript-generated code with 'view source'. This is because you are viewing the source generated by the webserver, and HTML code is generated by client-side javascript, after the webserver has loaded the HTML.

If you want to see the code generated by javascript, install Firebug for Firefox, and use the "Inspect Element" feature (right click on an element on the screen).

Calvin L
+1 for Firebug.
Lekensteyn
This can also be done natively in recent copies of Chrome and Safari (though Safari requires that the Web Inspector be enabled)
yc
Thanks for reply. I edited my question for explaining my purpose.
mavera
+1  A: 

The source is now available in variable source.

var source = document.getElementById(tableName).innerHTML;
// show the source
alert(source);
Lekensteyn