SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Echo javascript variable?!?!

    Not sure if this should be in the PHP forum or here but here goes...

    I'm trying to get this to work but with no luck...
    Code:
    <script type="text/javascript">
    var lala = top.location.href; 
    </script>
    
    <?
    $topurl = $_GET['lala'];
    echo 'Whats the url:'.$topurl;
    ?>
    What I'm trying to accomplish is to get the parent url from within an iFrame using PHP... I have surfed around the net and found that using javascript would work, but I'm not getting the javascript variable into the PHP...? Why? and are this the right way to go?!?!?

    Thanks in advance :-)

  2. #2
    SitePoint Zealot Gar onn's Avatar
    Join Date
    Feb 2011
    Location
    Belgium
    Posts
    130
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your code will not work becouse PHp is prossed before jour jaascript starts.
    So your PHp part will loas first.

    what you can do is sen the data via a redirect.

    howevver what is the aim of knowing the top location?

  3. #3
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Gar onn View Post
    Your code will not work becouse PHp is prossed before jour jaascript starts.
    So your PHp part will loas first.
    Is'nt the javascript running before the php?

    Quote Originally Posted by Gar onn View Post
    what you can do is sen the data via a redirect.
    Not sure what you mean?!?!

  4. #4
    SitePoint Zealot Gar onn's Avatar
    Join Date
    Feb 2011
    Location
    Belgium
    Posts
    130
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First you need to know that PHP code is ran at the server side;
    (so everything between <? ?> is executed before your browser starts reading the page.

    When the page is read, your browser runs all scripts between <script> tags. (ans parses HTML)

  5. #5
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Gar onn View Post
    First you need to know that PHP code is ran at the server side;
    (so everything between <? ?> is executed before your browser starts reading the page.

    When the page is read, your browser runs all scripts between <script> tags. (ans parses HTML)
    How can I change this?

  6. #6
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The reason for all this is that I'm trying to make my page available on facebook to. And as I'm making my page a FB app using iFrame I would like to know if the user is getting to my page through facebook og just as my plain http://www.mypage.com

    So I need to know if the page is as a child or as a parent... Does this make sense?!?!

  7. #7
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,872
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by jmansa View Post
    So I need to know if the page is as a child or as a parent
    JavaScript has no ability to see anything regarding separate frames if the domain is different.

    You might be able to tell where your visitor is from by checking the referer header in PHP (assuming your visitor hasn't turned it off)
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  8. #8
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, if I use this:

    Code JavaScript:
    alert(top.location.href);

    I get an "undifined" if it is in facebook (child) and the page url (www.mypage.com) if its parent... That is allright for me. Then I can set some rules if the page is undifined... But I still dont' know how to get the javascript variable down as a php variable...

    Any ideas?


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
  •