Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Suppose I have created a html page. Is is possible to write another html file using javascript when all the content of this new html file will be the same as existed file. Is is possible to get all the content from existed file using javascript and write a new html file?

HTML
<!DOCTYPE HTML>
<html>

  <body>
   <script>   
      
function traverseDOMTree(targetDocument, currentElement, depth)
{
  if (currentElement)
  {
    var j;
    var tagName=currentElement.tagName;
	
    if (tagName){
      targetDocument.writeln("<"+currentElement.tagName+">");
	  
	   var elid = currentElement.tagName;
	   
	
	   
	        var elem1 = document.getElementsByTagName(elid);

            var style = window.getComputedStyle(elem1[0], null);
            alert(style);
            var len = style.length;
			
            var str = '';
			
			for (i = 0; i < len; i++) {
			
			  //alert(i);
                if (window.getComputedStyle(document.getElementsByTagName(elid)[0], null).getPropertyValue(style[i]) != null)

                    str = str + style[i] + ':' + window.getComputedStyle(document.getElementsByTagName(elid)[0], null).getPropertyValue(style[i]) + ';\n';

            }
			
			targetDocument.writeln("<"+str+">");
		   
	  
	  }
    else
      targetDocument.writeln("[unknown tag]");

    var i=0;
    var currentElementChild=currentElement.childNodes[i];
    while (currentElementChild)
    {
      targetDocument.write("<br>\n");
      for (j=0; j<depth;>      {
        targetDocument.write("  ¦");
      }								
      targetDocument.writeln("<br>");
      for (j=0; j<depth;>      {
        targetDocument.write("  ¦");
      }					
      if (tagName)
        targetDocument.write("--");
      traverseDOMTree(targetDocument, currentElementChild, depth+1);
      i++;
      currentElementChild=currentElement.childNodes[i];
    }
    targetDocument.writeln("<br>");
    for (j=0; j<depth-1;>    {
      targetDocument.write("  ¦");
    }			
    targetDocument.writeln("  ");
    if (tagName)
      targetDocument.writeln("</"+tagName+">");
  }
}

function printDOMTree(domElement, destinationWindow)
{
  var outputWindow=destinationWindow;
  if (!outputWindow)
    outputWindow=window.open();

  outputWindow.document.open("text/html", "replace");
  outputWindow.document.write("<HTML><HEAD><TITLE>DOM</TITLE></HEAD><BODY>\n");
  outputWindow.document.write("<code>\n");
  traverseDOMTree(outputWindow.document, domElement, 1);
  outputWindow.document.write("</code>\n");
  outputWindow.document.write("</BODY></HTML>\n");
  
  outputWindow.document.close();
}



    </script>

 <div id="div2">
        <table style="border-top-style:solid">
            <tr>
                <td>Telephony    By Country</td>
                <td>Jan-2013</td>
                <td>Feb-2013</td>
                <td>Mar-2013</td>
            </tr>
            <tr>
                <td class="tdhighlight">Calls Offered</td>
                <td>33555</td>
                <td>28201</td>
                <td>27563</td>
            </tr>
            <tr>
			
		</tr></table>
</div>

   
    <button onclick="printDOMTree(document.getElementById('div2'));" style="width:100px">Go!</button>

  </body>
</html>


please help me as soon as possible.......... It is urgent!</br></br></br>
Posted
Updated 17-Aug-14 23:05pm
v3

1 solution

Yes, Its possible. You can just use One JS file for both html pages, or you can use it twice in each html pages.
 
Share this answer
 
Comments
sachi Dash 18-Aug-14 5:12am    
can you provide me a sample code for my given code ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900