我有一个由ASP生成的产品列表
我在html文件中有每个产品的产品说明

each html file is named: <product.id>.html<br/>
html file size is only 1-3 kb


在html文件中是<title><meta name="description" content="..." />
我想以一种有效的方式访问它们,以便将其输出为:

document.write(<product.id>.html.title);<br/>
document.write(<product.id>.html.description);


对于使用描述文件的单个产品,我有一个可行的解决方案-但希望找到一种更有效/更简单的方法。最好是,我想避免30个以上的隐藏iframe-谷歌可能认为我正试图篡改搜索结果并将我的页面列入黑名单...

当前代码:

<iframe src="myfile.html" id="product" style="display:none">&nbsp;</iframe>
<script type="text/javascript">
   document.getElementById('product').onload = function(){
   var d = window.frames[frame].document;
   var title = d.title : ' ';
   var keywords = d.getElementsByName('keywords')[0].getAttribute('content', 0) : ' ';
   var descript = d.getElementsByName('description')[0].getAttribute('content', 0) : ' ';
  }
</script>

最佳答案

如此处在另一个Stack Overflow question上所述,您可以使用:

document.title = "This is the new page title.";


并查看here给我们:

document.getElementsByTagName('meta').content = "New content here";


要么:

document.getElementsByTagName('meta').name = "NewName";


有了这些,您应该能够根据需要读取和写入标签,这里我仅使用了一些示例,当然还有更多示例。

08-05 07:23
查看更多