これを行う場合:
if (window.location.href.indexOf('http://www.leadcomm.net/cost-estimate/') == 0) {
//all jquery code here
}
'http://www.leadcomm.net/cost-estimate/'
これにより、URLの先頭にある任意のページにコードが制限されます。'http://www.leadcomm.net/cost-estimate/?qsname=qsvalue'
これは、URLのタイプも考慮します。ただし、サブディレクトリも使用でき'http://www.leadcomm.net/cost-estimate/dir1/dir2/'
ます。
これを行う場合:
if (window.location.href == 'http://www.leadcomm.net/cost-estimate/') {
//jquery code here
}
特にそのページに限定されます。
編集
考え直して、さらに良いオプションは.js
、そのすべてのコードを使用してドキュメントを作成することです。次に、ヘッダーで以下を実行して、ページに基づいて動的にロードします。これにより、必要な場合を除いて、コードがまったく読み込まれなくなります。
<script type="text/javascript">
if (window.location.href == 'http://www.leadcomm.net/cost-estimate/') {
var js = document.createElement('script');
js.setAttribute("type","text/javascript");
js.setAttribute("src", "jsfilename.js");
document.getElementsByTagName("head")[0].appendChild(js);
}
</script>