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
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy target window.location.href to iframe on new page

    I know next to nothing about javascript and I don't even know if this is possible. I need to target window.location.href to an iframe on a different page.

    So, right now, the piece of the code that redirects the browser looks like this:

    Code:
    window.location.href='http://www.somewhere.com/';
    Works great, brings it up in the same browser window. So now I need to modify the code so it goes to a different page and brings that page up in a specified iframe.

    I hope this makes sense. I really need help. And if it is not possible, I just need to know to abandon all hope.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Here you are:-

    Code:
    <iframe id = "myFrame"></iframe>
    
    <script type = "text/javascript">
    document.getElementById("myFrame").src = "http://www.google.com";
    </script>

    Quizmaster: What is 64 divided by eight?
    Contestant: Six.

  • #3
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok i can see how that would target it to an iframe on the same page. but I need it to go to an iframe on a different page.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,857
    Thanks
    78
    Thanked 4,417 Times in 4,382 Posts
    ??? A different page that is loaded into the same window? Or a different page in a different window?

    And do you "own" the "different page"? That is, can you modify its code?
    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.

  • #5
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    let me clairfy...

    for example...
    index.php has a form that when the submit button is clicked, it calls a function which does some stuff and then forwards the user to the next page, results.php.

    what I need it to do is...

    index.php has a form that when the submit button is clicked, it calls a function which does some stuff and then forwards the user to the next page, template.php with results.php loaded in myframe.

    Does that make better sense?

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,857
    Thanks
    78
    Thanked 4,417 Times in 4,382 Posts
    Okay, then you would be better off using PHP to accomplish this.

    Not hard. Simple example. *EXISTING* situation:
    Code:
    -- file: index.php
    <form action="results.php" method="post">
    <input name="foo">
    <input type="submit">
    </form>
    
    -- file: results.php
    <?php
        $foo = $_REQUEST["foo"];
        ... generate the page ...
    *Modified* situation:
    Code:
    -- file: index.php
    <form action="template.php" method="post">
    <input name="foo">
    <input type="submit">
    </form>
    
    -- file: template.php:
    <?php
        $foo = $_REQUEST["foo"];
        ...
    ?>
    <iframe src="results.php?foo=<?php echo $foo; ?>"></iframe>
    
    -- file: results.php
    <?php
        $foo = $_REQUEST["foo"];
        ... generate the page ...
    See? Just use your template.php page to pass the info along to the iframe page.

    If you use $_REQUEST then it works with either method=post data or with querystring data, so it's a really simple change.
    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.

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,857
    Thanks
    78
    Thanked 4,417 Times in 4,382 Posts
    If you think you *must* have a JavaScript solution, it can be done. But if your "results.php" page needs those <form> fields passed to it, anyway, it would be a much much messier solution.
    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.


  •  

    Posting Permissions

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