Check url using Javascript
Tags: javascript, url
Date: 18th July, 2010
Ages ago I commented somewhere and left a link to my site within the comment which included the ID of a div called learning_resources (http://mrportman.co.uk/#learning_resources). Since then the div no longer exists, but I wanted to offer those visitors the download still.
You can’t do anything with PHP because anything with a # isn’t passed to the server, so I had to resort to some Javascript and search the url:
$(document).ready(function() {
$url = $(location).attr(‘href’);
$string = “learning”
if ($url.search($string) == 24) {
<!– Do your thang here –>
}
});