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 3 of 3
  1. #1
    New Coder
    Join Date
    May 2013
    Posts
    13
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Open link in new window, but make it just like opening in original window

    I have an index.php that loads a page.php into a #result div. Page.php in turn has its own links and I have it so that when you click on one of these links it loads the respective page into the SAME #result div. Similarly that loaded page might have its own links and I want to continue loading content into the same div. The code for this is as follows:

    function loadPage(url){
    $("#wrapper").load(url, function(){
    $("#wrapper").find($('a')).each(function(){
    $(this).on('click', function(e){
    loadPage($(this).attr('href'));
    e.preventDefault();
    });
    });
    });
    }

    Say page.php has a link to page2.php.

    At the moment when I open the link to page2.php in a new window, it opens as page2.php. Same if I type the url to page2.php directly into my browser. I want it so that it opens as index.php but with page2.php loaded into its #result div(a duplicate of clicking the link normally in the original window).

    How do you do this?? I have tried lots of things including setting a session variable and passing to loadPage, but nothing seems to work.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    Why not just use an iframe instead of div?

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    And on top of that, unless you are really really careful about the contents of those various PHP files, you could well end up with illegal HTML and/or conflicting IDs and/or conflicting CSS and/or conflicting JavaScript when you just load them into <div>s instead of into <iframe>s.
    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.


  •  

    Tags for this Thread

    Posting Permissions

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