The current location is in location.href.
The location object also contains some other useful fields:
- location.hash: The part after the # in the URL
- location.host: Hostname including port (if specified)
- location.hostname: Just the hostname
- location.pathname: The requested URI without protocol/host/port; starting with a /
- location.port: The port - only if one is specified in the URL
- location.protocol: Usually 'http:' or 'https:' - mind the colon at the end
In your case the most fail-safe way to check if the filename is trucks.php is this:
var parts = location.pathname.split('/');
if(parts[parts.length - 1] == 'trucks.php') {
location.href = 'some-other-page';
}
If you want to redirect without keeping the current page in history, use the following code instead of the location.href assignment:
location.replace('some-other-page');