Reading HTML header info of files via JS

Posted by Morten Repsdorph Husfeldt on Stack Overflow See other posts from Stack Overflow or by Morten Repsdorph Husfeldt
Published on 2012-11-22T10:55:36Z Indexed on 2012/11/22 10:59 UTC
Read the original article Hit count: 179

Filed under:
|

I have a product list that is generated in ASP. I have product descriptions for each product in an HTML file. Each HTML file is named: <product.id>.html. Each HTML file size is only 1-3 kb.

Within the HTML file is <title> and <meta name="description" content="..." />. I want to access these in an efficient way so that I can output this as e.g.:

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

I have a working solution for the individual products, where I use the description file - but I hope to find a more efficient / simple approach. Preferably, I want to avoid having 30+ hidden iframes - Google might think that I am trying to tamper with search result and blacklist my page.

Current code:

<script type="text/javascript">
  document.getElementById('produkt').onload = function(){
    var d = window.frames[frame].document;
    document.getElementById('pfoto').title = d.title : ' ';
    document.getElementById('pfoto').alt = d.getElementsByName('description')[0].getAttribute('content', 0) : ' ';
    var keywords = d.getElementsByName('keywords')[0].getAttribute('content', 0) : ' '; };
</script>

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about header