如果在某个网页上运行脚本

zma*_*anw 4 javascript browser web

我有一个加载音乐播放器的脚本,但我只想在播客页面上运行它.

应该是这样的 if window.location is example.com/podcasts then <script> blah </script>

我怎样才能做到这一点?谢谢!

小智 7

javascript将是:

<script type="text/javascript">
    if(window.location.pathname == '/podcast') {
        // script body here
    }
</script>
Run Code Online (Sandbox Code Playgroud)