I have a script that loads a music player but I only want to run it on my podcasts page.
It should go something like if window.location is example.com/podcasts then <script> blah </script>
How can I do this? Thanks!
I have a script that loads a music player but I only want to run it on my podcasts page.
It should go something like if window.location is example.com/podcasts then <script> blah </script>
How can I do this? Thanks!
The javascript would be:
<script type="text/javascript">
if(window.location.pathname == '/podcast') {
// script body here
}
</script>
I dont know if this helps but on this page if you use window.location you can do something like the following:
window.location['href']
=> "http://stackoverflow.com/questions/9709337/run-script-if-on-certain-webpage"
window.location['pathname']
=> "/questions/9709337/run-script-if-on-certain-webpage"
you can then do something like this if your using JQuery
if( window.location['pathname'] === 'desired_path')
$('body').append($('<script ... ></script>'))