SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict mcrumlish's Avatar
    Join Date
    Jan 2002
    Posts
    384
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can I print a variable passed in a URL using javascript?

    Hi,

    I have code for an iframe as follows:

    PHP Code:
    <iframe src="http://www.thesite.com/test.html?uid=125433" marginwidth="0" marginheight="0" width="220" height="120" hspace="0" vspace="0" frameborder="0" scrolling="no"></iframe>
    </
    iframe
    Is there any way I can read the value of UID and output this in the target page of the iframe using javascript?

    Thanks,
    Martin

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is the URL of the iframe is in the same domain as the one you're operating in?
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    SitePoint Addict mcrumlish's Avatar
    Join Date
    Jan 2002
    Posts
    384
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes

  4. #4
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, then. Assuming you only need the uid value

    var uid = document.frames[0].src.replace( /^[^=]+\=/, '' );

    This will return it as a string, so you'll need to run parseInt() if you intend to use it as a Number in JS.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  5. #5
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    beetle...

    document.frames[0].src

    Maybe in iemac, elsewhere it's [window.]frames
    And: HTMLIFrameElement has a .src property, but the iframe's window object uses the standard Location object for setting & getting.
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" 
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    <head>
    <title>untitled</title>
    </head>
    <body>
    <iframe id="foo" src="http://www.thesite.com/test.html?uid=125433" marginwidth="0" marginheight="0" width="220" height="120" hspace="0" vspace="0" frameborder="0" scrolling="no"></iframe>
    <p>
    <strong>The user id for this page is <span style="color:#66c;">
    <script type="text/javascript">
    var uid = document.getElementById('foo').src.split('=')[1]; //.src.replace( /^[^=]+\=/, '' ); nice too
    document.write(uid);
    </script>
    </span>.</strong>
    </p>
    </body>
    </html>
    ::: certified wild guess :::

  6. #6
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh ya - been too long since I did frames....
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  7. #7
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ...can't be 'too long' since we've done frames...
    ::: certified wild guess :::


Bookmarks

Posting Permissions

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