The JavaScript code snippet shown below is used to determine the use of the back button and navigation within the site. This information can be used for features such as opening skip, for example.
var ref = document.referrer;
var hereHost = window.location.hostname;
var sStr = "^https?://" hereHost;
var rExp = new RegExp( sStr, "i" );
if( ref. length == 0 ) {
// no referrer
}
else if( ref.match( rExp ) ) {
if (window.performance) {
// console.log(performance.navigation.type);
if (performance. navigation.type === 0) {
// TYPE_NAVIGATE
// load from within site
}
else if (performance.navigation.type === 1) {
// TYPE_RELOAD
// reload load
}
else if ( performance.navigation.type === 2) {
opening_skip = true;
// TYPE_BACK_FORWARD
// loading by returning
}
else {
// TYPE_RESERVED
}
}
else {
}
}
else {
}
This code determines whether the user has navigated through the site, reloaded the page, or used the back button. Different processes can be executed for each of these situations.