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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.