1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

iframe get element by id

Discussion in 'HTML & JavaScript' started by baxxx, Apr 20, 2012.

Tags:
  1. baxxx

    baxxx Junior Member

    Joined:
    Mar 25, 2012
    Messages:
    179
    Likes Received:
    43
    Occupation:
    hustler
    Location:
    EU
    Home Page:
    Hi im developing an web app that needs to acess an variable from external webpage, not owned by me. That variable is located in <span> section and obiously has its inique ID.

    The pseudocode of an app looks something like this.
    Code:
    <html>
    <script>
    var a = get elementy by id (price) from (external-page dot com); // gets variable from external page, where ID of variable =price
    document.write (a); // writes variable to my document/webapp
    </script>
    </html>
    
    Can someone help me with real html/js code?
     
    Last edited by a moderator: Apr 20, 2012
  2. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,468
    Likes Received:
    10,143
    You cannot get the html of a third party site using Javascript due to modern browsers security policies.You can get the html only from pages in the same domain. :)
     
  3. roster67

    roster67 Registered Member

    Joined:
    Mar 27, 2012
    Messages:
    69
    Likes Received:
    10
    Hopefully, there is no way to make this work using only javascript if the foreign domain you try to access doesnt support procedure like JSONP, C.O.R.S or postMessage.

    Depending what you want to reach exactly, you could find a workaround using php/javascript but not js alone.

    You should first try to learn js and web programming before asking question that has been answered hundred times over the net. I know a good site for this: google.com
     
  4. Narrator

    Narrator Power Member

    Joined:
    Oct 5, 2010
    Messages:
    507
    Likes Received:
    396
    Occupation:
    Internet Marketing
    Location:
    /dev/null
    Does it need to be in an iframe? You could do it by using ajax to call a php script that scrapes the site for the variable.