Run your script if on a specific web page

I have a script that loads a music player, but I only want to run it on my podcast page.

It should look something like this: if window.location is then <script> blah </script>

How can i do this? Thank!


source to share

2 answers

javascript will look like this:

<script type="text/javascript">
    if(window.location.pathname == '/podcast') {
        // script body here




I don't know if it helps, but on this page, if you are using window.location, you can do something like the following:

=> ""
=> "/questions/9709337/run-script-if-on-certain-webpage"


you can do something like this if you are using JQuery

if( window.location['pathname'] === 'desired_path') 
   $('body').append($('<script ... ></script>'))




All Articles