views:

12

answers:

2

I'm looking at using AJAX to allow some content within part of a page to be reloaded without reloading the entire web page (eg things like overview, reviews, specifications, etc pages about a single item).

The problem is however I still want to allow users to open these items in a new tab or window (using the normal systems for their web browser such as right clicking the link and picking "Open Link in New Tab) rather than just left clicking the link).

Is it at all possible to do this, or is it just generally best practice to reload the entire page in cases like this?

+1  A: 

It's very much doable. You simply need to provide an href and an onclick in your links.

The href will activate if the user has no JS, or if the user decides to open the link in a special way (new tab, etc.)

The onclick will activate on "normal" clicks of the link. You can then cancel the default action (by returning false or using your JS lib of choice's way to do it) and do your ajax stuff.

Jani Hartikainen
A: 

It is possible, in fact its even possible to set up a timer to update portions of pages periodically. If you are using jquery it'd be something like this:

setInterval(function() {
         $('#your-div').load('your-server-side-request.php');
         }, 3000);

of course you could simply bind to a link, and on refresh use .load().

OR you could even just do this with normal javascript and use my script above as pseudocode essentially.

Parris