www.webdeveloper.com
Results 1 to 8 of 8

Thread: Reading html header info of files via JS

Hybrid View

  1. #1
    Join Date
    Nov 2012
    Posts
    7

    Reading html header info of files via JS

    I have a product list that is generated by asp
    I have product description for each product in a html file

    each html file is named: <product.id>.html
    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);
    document.write(<product.id>.html.description);

    I have a working solution for the individual product, where I use the description file - but hope to find a more efficient / simple approach:


    <iframe src="" id="product" style="width:100%; margin-top:-20px;">&nbsp;</iframe>
    <script type="text/javascript">
    ;(function(frame){
    document.getElementById(frame).onload = function(){
    var d = window.frames[frame].document, dt, dd, dk;
    document.getElementById('pfoto').title = (dt = d.title)? dt : ' ';
    document.getElementById('pfoto').alt = (dd = d.getElementsByName('description')[0])? dd.getAttribute('content', 0) : ' ';
    var keyords = (dk = d.getElementsByName('keywords')[0])? dk.getAttribute('content', 0) : ' ';
    };
    })('product');
    </script>

  2. #2
    Join Date
    Nov 2012
    Posts
    7
    Have simplified my code from above a bit:

    <iframe src="myfile.html" id="product" style="width:100%; margin-top:-20px;">&nbsp;</iframe>
    document.getElementById('product').onload = function(){
    var d = window.frames[frame].document;
    var titel = d.title : ' ';
    var keywords = d.getElementsByName('keywords')[0].getAttribute('content', 0) : ' ';
    var beskrivelse = d.getElementsByName('description')[0].getAttribute('content', 0) : ' ';

  3. #3
    Join Date
    Nov 2012
    Location
    France
    Posts
    4
    Throughout the great pattern of things you receive a B+ with regard to effort and hard work. Where exactly you lost us ended up being on the facts. As it is said, details make or break the argument.. And that couldn't be much more accurate here. Having said that, allow me say to you what did give good results. Your text is highly powerful and this is probably the reason why I am taking the effort to comment. I do not really make it a regular habit of doing that. Second, despite the fact that I can certainly notice the leaps in logic you make, I am not really certain of how you appear to unite the points which produce the actual final result. For the moment I will yield to your point however trust in the foreseeable future you link your dots much better. best wishes

  4. #4
    Join Date
    Nov 2012
    Posts
    7
    Yes, the above solution works...
    However, it has a couple of drawbacks.

    First: It retrieves the entire file - I only need the header info.
    Second: I only need header info, so all iframes will be hidden: display:none, Hence, I will have 30+ hidden divs on the page
    Third: Google is likely to read 30+ hidden iframes as an attemt to manipulate data, and therefore downrank / blacklist the page.

    Therefore, I hope to find a solution that fetches the file or - if possibly - only the few parameters that I need.

  5. #5
    Join Date
    Nov 2012
    Location
    France
    Posts
    4
    I have observed in the world of today, video games are classified as the latest trend with children of all ages. Many times it may be extremely hard to drag your family away from the activities. If you want the best of both worlds, there are plenty of educational games for kids. Good post. best wishes
    greatful escort girls Paris today

  6. #6
    Join Date
    Mar 2011
    Posts
    1,139
    AJAX can use a 'HEAD' request (as opposed to 'GET' or 'POST'), and you can use getResponseHeader() to retrieve specific values. A quick Google search will show you lots of examples.
    Rick Trethewey
    Rainbo Design

  7. #7
    Join Date
    Nov 2012
    Location
    France
    Posts
    4
    Hiya, I'm really glad I've found this information. Today phorumgers publish only about gossips and net and this is actually frustrating. A good phorum with interesting content, this is what I need. Thank you for keeping this web-site, I'll be visiting it. Do you do newsletters? Cant find it. wish you luck
    awesome escort girls Paris forever

  8. #8
    Join Date
    Nov 2012
    Posts
    7
    Have found this solution - not elegant, but it works:

    Code:
    <script>
      var xhr = $.ajax({
        type: "GET",
        url: "/files/billeder/ecom/beskrivelser/<product.id>.html",
        success: function(msg){
        msg = msg.split('content="')[1];
        msg = msg.split('"')[0];
        document.getElementById("<product.id>").innerHTML = "<p>" + msg + "</p>";
    Anyone that has a better way of searching the 'msg' and isolate the data - and if possible only read the header and not the entire document.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles