Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Feb 2005
    Posts
    191
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Pulling title from iframe cross domain

    Anyone know if there is a way to get the title string from an iframe src coming from another domain?

  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,375
    Thanks
    11
    Thanked 592 Times in 572 Posts
    you can get the .src attrib , but title sound more like it's coming from the document itself, which historically, you can't reach.

    if you own the iframe'd page, you can add message passing events to respond to queries from the framing page. look into window.postMessage()...
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%

  • #3
    Regular Coder
    Join Date
    Feb 2005
    Posts
    191
    Thanks
    6
    Thanked 0 Times in 0 Posts
    looking into it. looks promising but haven't figured it out yet. will keep looking.

  • #4
    Regular Coder
    Join Date
    Feb 2005
    Posts
    191
    Thanks
    6
    Thanked 0 Times in 0 Posts
    any other suggestions? unable to get this to work

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,014
    Thanks
    79
    Thanked 4,435 Times in 4,400 Posts
    Unless you have hundreds of possible <iframe> contents, why not just set up a table of correspondence between the .src of the <iframe> and the <title> of it?

    That is:
    Code:
    var theTitles = {
        "page2" : "Alligators",
        "page3" : "Bananas",
        ...
       };
    
    var theTitle = theTitles[ iframeSrcStrippedToNameWithoutExtension ];
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,375
    Thanks
    11
    Thanked 592 Times in 572 Posts
    Quote Originally Posted by wyclef View Post
    any other suggestions? unable to get this to work
    you can use YQL to fetch html from almost any page.
    just grab the title element, and use the json w/callback flavor YQL output...
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%

  • #7
    Regular Coder
    Join Date
    Feb 2005
    Posts
    191
    Thanks
    6
    Thanked 0 Times in 0 Posts
    i think the yql/json option may be out of my league but what old pedant is talking about could work. i only have about a dozen or so iframe src. could you elaborate on this table of correspondence?


  •  

    Posting Permissions

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