Jump to content

Detect if link opened in new tab or window or direct url access


pintee

Recommended Posts

I was wondering if anyone know how to achieve this.

I have an index.php that loads a file page.php into a div using jQuery. This page.php has a link that when you click it loads page2.php into the same div(so the url always stays as index.php).

I want to make it so that, if you open the link on page.php in a new tab or window, instead of loading page2.php, it redirects to index.php(with page.php in the div). Same if you type in the link to page2.php directly into the browser.

 

Include a special flag in the AJAX URL so you know the request is coming from the AJAX and not a normal request. If it's not present then redirect.

 

By the way, what you're doing is horrible. How am I supposed to bookmark a page on your site? Link it to friends? Search engines will absolutely hate it.

Change your AJAX URL to something like

/page2.php?ajax
then redirect if !isset($_GET["ajax"]).

 

Yes, it does mean that someone could go to "page2.php?ajax" to see the page without a redirection, but it is not possible to strictly allow AJAX only - this is basically as close as you can get.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.