How to get meta tags content of parent page from an iframe using jQuery

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mudassir
    New Member
    • May 2012
    • 85

    How to get meta tags content of parent page from an iframe using jQuery

    Dear all..
    I want to get the meta description and image in the head section of parent page from the iframe.

    In a simple page I did it like this :
    Code:
     <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
        <title></title>
         <link rel="image_src" href="source to my image" />
        <script type="text/javascript">
    
            function addToInterest() {
                var meta = document.getElementsByTagName("title")[0].innerHTML;
                meta += "\n";
                meta += $('meta[name=description]').attr("content");
                meta += "\n";
                meta += 
                meta += $(location).attr('href');
                meta += "\n";
                meta += $('link[rel=image_src]').attr("href");
                alert(meta);
            }
        </script>
    This works fine, but when inside an iframe, I want to get the title, location, meta descripton and the image of the parent page using jQuery.

    For title and url of the parent page I have used:
    Code:
    var meta = parent.document.getElementsByTagName("title")[0].innerHTML;
    meta += document.referrer;
    its working fine also. but for the meta description and the image i am facing problem.
    Any sample code for this please..


    Regards,
    Mudassir
    Last edited by Frinavale; Jul 4 '13, 01:12 PM.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    I don't think you can access elements of an iframe from the parent page; likewise I don't think you can access elements of a parent page from the iframe.

    I remember I was able to do something with cookies but that I felt it was a bit "hacky".

    -Frinny
    Last edited by Frinavale; Jul 9 '13, 12:53 PM.

    Comment

    • Mudassir
      New Member
      • May 2012
      • 85

      #3
      Frinny:

      i get the title and url of the parent page from the iframe, i have mentioned it in the post.
      i solved my problem by using Web User Control instead of iframe
      :)

      Regards:
      Mudassir

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        That is a good idea :)
        It is good for search engine optimization not to use iframes :)

        I'm glad you solved your problem.

        -Frinny

        Comment

        Working...