SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Aug 2002
    Location
    UK
    Posts
    124
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to pass a variable to a specific frame?

    Well, I've done a search and I can't quite find the answer to this question. Or perhaps I did, but being a newbie didn't recognise it.

    I want to link from a normal page taking a variable (an item which the user has selected). The link is to a frameset with two frames. One of the frames needs the variable, but I need the whole frameset to display when the link is done.

    Should I link to the frameset or the frame (in which case how does the rest of the frame get displayed). If I link to the frameset, how does the particular frame get the variable?

    I am using PHP, but I'm not sure if that is relevant.

    Thanks.

  2. #2
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the answer you are searching for: http://www.sitepointforums.com/showt...threadid=66069

  3. #3
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, I read your question one more time... the problem is: how to send a variable to the page in the frame (not how to send the page name as a variable)?
    If you only have one variable, then it's easy

    The link:
    <a href="frame.php?page=test.php?var1=123">Test1</a>

    The page frame.php:
    <?
    $page = $_GET["page"];
    if(empty($page)) $page = "default.php";
    ?>
    <frameset rows="100, *">
    <frame name="menu" src="menu.php">
    <frame name="main" src="<?=$page?>">
    </frameset>

    The page test.php:
    <?
    $var1 = $_GET["var1"];
    echo "var1 = $var1";
    ?>

    The result in the "main" frame should be:
    var1 = 123

    But what if we have more than one variable?

    The link...
    <a href="frame.php?page=test.php?var1=123&var2=456">Test2</a>
    ...gives this result*:
    var1 = 123, var2 =

    Then we have to link first to the page that should be in the frame...
    <a href="test.php?var1=123&var2=456">Test3</a>
    ...and then check in test.php...
    <script language=javascript>
    if (window == top)
    {
    top.location.href = 'frame.php?page=' + escape(location.href.substring(location.href.lastIndexOf('/') + 1));
    }
    </script>
    ...and finally we get this result* (with test.php in the "main" frame):
    var1 = 123, var2 = 456

    *(test.php changed to
    <?
    $var1 = $_GET["var1"];
    $var2 = $_GET["var2"];
    echo "var1 = $var1, var2 = $var2";
    ?>
    of course...)

    Edit: Why am I not using urlencode()?
    Because if I mail a link like...
    <a href="frame.php?page=<?=urlencode("test.php?var1=123&var2=456")?>">
    ...some mail clients (Outlook Express for example) cannot display the link correctly - the result is the same as without urlencode()
    Last edited by jofa; Sep 12, 2002 at 18:43.

  4. #4
    SitePoint Zealot
    Join Date
    Aug 2002
    Location
    UK
    Posts
    124
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks jofa - you understood the question correctly and I have tried both your solutions - and they both work great - I will need the multiple variables solution.

    What would have been the advantage of using urlencode()? The mail problem would not be an issue in this particular case as the pages are for database update and will have restricted access.

    Cheers
    Jack

  5. #5
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    With
    <a href="frame.php?page=<?=urlencode("test.php?var1=123&var2=456")?>">
    you go to the frameset directly

    With
    <a href="test.php?var1=123&var2=456">
    you go first to test.php, then to frame.php, and you need that javascript that redirects to the frameset


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
  •