Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving dynamic content in HTML.

Status
Not open for further replies.

jagi

Programmer
Mar 13, 2005
48
US
Hi,

I am generating a HTML table dynamically with the following code:

for(i=0; i<noRows; i++) {
current_cell=document.createElement("TD");
current_text=document.createTextNode('-');
current_cell.appendChild(current_text);
row.appendChild(current_cell);
}

I call this function onload. The problem arises when i need to save the page. I need to have a - save as HTML option. When I do save as HTML page, it doesnt save the generated content.

How can i solve this ? Any suggestions ?

Thanks.
 
One solution would be to display the html source code and allow the user to copy and paste it.

Another solution would be to create a browser extension that allowed you to save the data.

What situation are you using this feature in? A website? Intranet app? For personal use?

What is the purpose or function of the website or intranet app?
 
If you redesign the page to write the table dynamically on the server (ASP, PHP, Coldfusion, whatever is available), then the HTML code will exist for the client computer without being generated with client-side JS. Then saving the page will do what you said you want.

Lee
 
I think you want to view on the client side the effect of HTML changes made.

Makes sense. That would be a nice diagnostic to view it as it runs. It would also be useful as a code-stealer to preserve any state of a dynamic webpage for static use.

Here is an example I have used on IE.

(1) The first UMakeIt function just does a sample dynamic HTML so that when you view it later, you will see the change.

(2) The other change is a DOM change that alters the display attribute of a non-display div.

When you click the action, a new window will appear --- a view source there will show the HTML as it ... AFTER all dynamic changes are in place.




Code:
<head>

<script language="javascript">


function Umakeit(pcol) {
      var itext = idx1.innerText ;
      idx1.innerHTML  =  '<font color=red>'  +itext+   '</font>' ;

}


function WDiagViewDynHTML()  {

var WN7z=open('','Z6','width=400,height=200,scrollbars,resizable,menubar');
DL5e=document.links;
with(WN7z.document)
   {write(document.getElementsByTagName('body')[0].innerHTML);
    void(close())}
WN7z.focus();


}

</script>

<body onload="Umakeit('red'); ">

<span id=idx1>Invisible Diag Area Follows:</span>


<span onclick="X_DiagToolKit.style.display='block';">Reveal  Diag Actions &nbsp;&nbsp;&nbsp;
</span>

<div id=X_DiagToolKit style='cursor:hand; display:none; '>

<span onclick="javascript:WDiagViewDynHTML();"
  >Show Dynam HTML</span>
<br>
 
By the way, if you string out the contents of the function WDiagViewDynHTML without a function header nor name nor enclosing braces...

It can run as a URL bookmarklet to view the currently altered HTML of any frameless dynamic web page:


Place the following type of URL (with a complete strung-out function) in the browser address box and click GO.

javascript:var WN7z=open('','Z6','width=400,height ...

A new window with the body will display, just View Source.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top