jeremy-h of Web Development
11/1/2017 - 5:13 PM

Page Location for Hidden Form Field

Create a hidden field with a class of .page-locator. The script will locate the page URL and it can then output that string.

$(window).load(function(){
    var pageLocation = window.location.pathname,
        locText = pageLocation + " is the current page";

    if (pageLocation == "/") {
        console.log( "home page" ); 
        $('.page-locator').attr('value', 'home page'); // class of hidden input field
    } else {
        console.log( locText ); 
        $('.page-locator').attr('value', locText ); // class of hidden input field
    }
});