如何在从另一个现有页面获取内容后创建一个html页面,它将与现有的html页面相同? [英] How can I create a html page after getting the content from another existent page and it will be same as the existed html page ?

查看:59
本文介绍了如何在从另一个现有页面获取内容后创建一个html页面,它将与现有的html页面相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我创建了一个html页面。当这个新的html文件的所有内容与现有文件相同时,可以使用javascript编写另一个html文件。是否可以使用javascript从现有文件中获取所有内容并编写新的html文件?



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?

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

推荐答案

是的,它可能。您可以在两个html页面中使用One JS文件,也可以在每个html页面中使用两次。
Yes, Its possible. You can just use One JS file for both html pages, or you can use it twice in each html pages.


这篇关于如何在从另一个现有页面获取内容后创建一个html页面,它将与现有的html页面相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆