我有一个加载音乐播放器的脚本,但我只想在我的播客页面上运行它。如果在某些网页上运行脚本
它应该像if window.location is example.com/podcasts then <script> blah </script>
我怎样才能做到这一点? 谢谢!
我有一个加载音乐播放器的脚本,但我只想在我的播客页面上运行它。如果在某些网页上运行脚本
它应该像if window.location is example.com/podcasts then <script> blah </script>
我怎样才能做到这一点? 谢谢!
的JavaScript将是:
<script type="text/javascript">
if(window.location.pathname == '/podcast') {
// script body here
}
</script>
谢谢!如果我想在主体中插入一个脚本,如这样的工作吗?我没有访问脚本本身的权利? – zmanw 2012-03-14 23:59:54
如果你使用jQuery,你可以使用下面Mike写的一些代码: $('body')。append($('')) – kingcoyote 2012-03-15 00:55:59
我不知道这一点,但可以帮助这个页面上,如果你使用了window.location你可以做类似如下:
window.location['href']
=> "http://stackoverflow.com/questions/9709337/run-script-if-on-certain-webpage"
window.location['pathname']
=> "https://stackoverflow.com/questions/9709337/run-script-if-on-certain-webpage"
那么你可以,如果你使用JQuery
if(window.location['pathname'] === 'desired_path')
$('body').append($('<script ... ></script>'))
做这样的事情
你确定,你需要检查,是否需要在JAV球员ascript? – kirilloid 2012-03-14 20:02:31