如果在某个网页上运行脚本 [英] Run script if on certain webpage

查看:54
本文介绍了如果在某个网页上运行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

如果window.location是example.com/podcasts那么它应该类似于,然后< script> blah< / script>

It should go something like if window.location is example.com/podcasts then <script> blah </script>

我该怎么做?
谢谢!

How can I do this? Thanks!

推荐答案

javascript将是:

The javascript would be:

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

这篇关于如果在某个网页上运行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆