In the courtyard of the group, someone asked such a question:
A page submits the form to the B page, then the B page is back, if the a page is judged by direct access or back in? I don't want to change the B page.
So in the spirit of enthusiastic people's thoughts, I helped him to engage, first I think of window.history, but unfortunately, it does not provide the corresponding attributes, but provides a way forward and backward jump. So I found the document.referrer, this can get the last URL of the page, so I just want to determine if the previous URL is b] not OK? However, it backfired because the browser's forward and backward are not supported when using Document.referrers! First of all, the following is a summary of the online document.referrer and its compatibility: Document.referrers
One, in terms of the use of the document.referrer want to be able to track the browser-side behavior. If a page A is opened, then the browser may occur on the action of the user operation, JS code two. Let's take a look at what users might do when they open page A:
1 |
Enter the address of a directly in the address bar |
2 |
From page b, click Link A to jump to page a. |
3 |
From page B, right-click link A and open in a new window |
4 |
Right click on link A from page b and open in new tab |
5 |
Drag link A to the address bar |
6 |
Drag link A to tab bar |
7 |
Use the browser's forward, Back button |
Note that the link here refers to the <A> tag, but if there is an event or target it is another matter.
JS opens the page the possible way:
1 |
Modify Window.location |
2 |
Using window.open |
3 |
Click Flash |
The above lists some of the ways the client can open the page, and also enables page A to be presented to visitors through the server-side redirection technology.
The following is a specific browser test, if this is the case above, how Document.referrer behaves:
Serial number |
Scene |
IE8.0 |
FF3.6 |
FF4.0 |
Chrome |
1 |
Enter the address of a directly in the address bar |
" " |
" " |
" " |
" " |
2 |
From page b, left click on Link a,a page to replace b page (target= ' _self ') |
√ |
√ |
√ |
√ |
3 |
From page b, left click Link A,a opens in a new window (target= ' _blank ') |
√ |
√ |
√ |
√ |
3 |
From page B, right-click link A and open in a new window |
√ |
√ |
√ |
" " |
4 |
Right click on link A from page b and open in new tab |
√ |
√ |
√ |
" " |
5 |
Drag the mouse link A to the address bar |
/ |
" " |
" " |
" " |
6 |
Drag the mouse link A to the tab bar |
" " |
" " |
" " |
" " |
7 |
Use the browser's forward, Back button |
Keep |
Keep |
Keep |
Keep |
8 |
Modify Window.location open a page (same domain) |
" " |
√ |
√ |
√ |
9 |
Open a page with window.open |
" " |
√ |
√ |
√ |
10 |
Click Flash to open a page |
|
|
|
|
11 |
Server Redirect to page a |
" " |
" " |
" " |
" " |
Where, "" represents an empty string, √ indicates that the source page can be correctly judged, and keeping means that using forward and backward will not change the referrer of the page. From this table, you can see that document.referrer can cover about half of the case. However, for some of the more commonly used operations, such as using the mouse to drag the link to the tab bar, forward and backward, etc. are not able to make the correct processing.
Ii. Sources of Document.referrer
The browser sends an HTTP request when it requests page A to the server. The header of the request takes the Referer attribute, and after the server receives the request, it can extract the Referer from the header to determine which page the visitor originated from.
In general, what is referer in the header that is sent when the browser requests a, then what is the Document.referre value after getting the a page. is a request for a page of Header,a Document.referre for http://localhost/Test/b.html.
If you do not include Referre in the header, you will be assigned an empty string when you use Document.referre to fetch it.
Iii. about HTTPS requests
If you click on the HTTPS link on a normal HTTP page, you can attach the Referer information to the HTTPS request header, and then you can still use Document.referre to get the normal HTTP page on the HTTPS page.
Similarly, if you clicked on another HTTPS link on one of the HTTPS pages, you can attach the Referer message to the requested header.
However, if you clicked on an HTTP link from an HTTPS page, unfortunately, the HTTP request header could not contain information about the HTTPS page, which could be a protection against HTTPS pages.
So, the use of document.referrer also not, then how to do?
Here are my two ideas:
1, use the session to store an additional variable to determine whether the user is back from B to a.
2, deny the page cache, because Document.referer can no longer move back when the role of the cache is a curse. But not verified, I want to verify next. Here for the time being.
How to get URL access history