JavaScript current URL check -
i wondering how javascript check if user on url can build if statement result.
my reasoning if user clicks on link in menu , on trucks.php javascript redirect them page. if not on trucks.php directed different page.
cheers guys.
the current location in location.href
.
the location object contains other useful fields:
- location.hash: part after # in url
- location.host: hostname including port (if specified)
- location.hostname: hostname
- location.pathname: requested uri without protocol/host/port; starting /
- location.port: port - if 1 specified in url
- location.protocol: 'http:' or 'https:' - mind colon @ end
in case fail-safe way check if filename trucks.php this:
var parts = location.pathname.split('/'); if(parts[parts.length - 1] == 'trucks.php') { location.href = 'some-other-page'; }
if want redirect without keeping current page in history, use following code instead of location.href
assignment:
location.replace('some-other-page');
Comments
Post a Comment