0

I have this page, with a Default.aspx working as a "master" would work, and loading child pages with jQuery's load() function. Something Like this:

    <ul id="navigation>
        <li><a href="Item1.aspx"> Item 1</a></li>
         <li><a href="Item2.aspx"> Item 2</a></li>
    </ul>
    <div id="contend">
         <!-- Ajax loaded pages goes here -->
    </div>
    <div id="footer">
    </div>

The problem is: when the user clicks on some item and, let's say, chooses to open on a new window (tab), He will obviously see just the items from that page, not the navigation, footer and anything else from the default page...

I'm searching for a workaround..

maybe with anchor control via url? like #item1

3
  • Vitor, what happens if user has javascript turned off? Then, it's best if the link actually redraws the page with the new content in it. This is called progressive enhancement or graceful degradation, and it's good practice even if almost everyone has javascript enabled. Commented May 20, 2011 at 6:08
  • You mean, redraws the page even if my call was made by the ajax menu? Wouldn't this be off the whole purpose of it? Commented May 20, 2011 at 13:52
  • What I mean is that it should redraw the page if ajax doesn't work because there's no javascript Commented May 20, 2011 at 17:06

1 Answer 1

2

Send an additional parameter with ajax. So you can determine if the request was made by ajax and choose how to build the response.

Example as requested:

<script  type="text/javascript">
$(
   function()
   {
    $('#navigation a')
      .click(
              function(e)
              {
                e.preventDefault();
                $('#contend').load(this.href,{'isAjaxRequest':true});
              }
            );
   }
 );
</script>

If a user clicks the link the usual way, there will also be send a POST-parameter named "isAjaxRequest" , you can check for this parameter, and if it exists, output only the fragment for #contend, otherwise the whole page including header, footer and so on.

Sign up to request clarification or add additional context in comments.

1 Comment

Could you provide a (really simple) example based on my structure? I'm not sure how I could rebuild the structure..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.