Can I find out when people open a link on my site in a new tab?

What I want to know is when people click on a link on my site (internal link - not on other websites), if they just clicked on it or clicked on it (or right-click - open in a new tab )

I am using PHP.

So, an example: The person is on page 1 and click on the link for page2. When they are on page2, I want to know where they came from (_server ['http_referer'] gives me this), but I also want to know if they opened the page in a new window / tab. I need to know this because of the history return button on the page.

The reason for this is to know the browsing history around the site - I create a session to track browsing history (so that I can return one page back, two pages back or three pages back at any given time), but I don’t need to Sessions conflict between tabs so that each tab has its own browsing history. This is why I need to create a new session for each open tab.


What I found as a possible solution to my problem is to use javascript like this:

<script> var history_status = history.length; var referrer_site = document.referrer; if(history_status > 1 && referrer_site != "") { alert(referrer_site); } else { alert('No referrer site'); } </script> 

I need to change it a bit, but this was my first demo to check if it works (and it was)

First I need to find what the browser uses, because history_status gives 0 for the first page of the story when you use IE, but 1 if you use Firefox or Chrome.

+4
source share
1 answer

It doesn’t look like a good user interface. The back buttons and the ability to open new tabs are what users expect them to behave in a certain way. Personally, I would be unpleasant. What is the point of a new tab if they cannot create their own unique browsing history just for this tab?

If you really really wanted to do this. Create a cookie with a number, on each page load the number up and save the URL of the page in your database for this session. On page loading, download the trophy history and load them into your browser history using JavaScript. EEEK.

+1
source

Source: https://habr.com/ru/post/1379305/


All Articles