LoginSignup
9
10

More than 3 years have passed since last update.

特定のページでのみjsを発火させる方法

Last updated at Posted at 2019-07-18

はじめに

jsを特定のページでのみ発火させたいと考え、調べたことについてまとめる。

やり方

やり方はとてもシンプルで、

edit.js
if(document.URL.match(/edit/)){
    発火させたいjsの内容

これだけでjsを発火させるページを指定できます。
この場合はurlに’edit’という文字が入っているページでのみjsが発火します。

欠点

指定した文字の入ったurlが複数あると複数のページでjsが発火してしまいます。
どのページとも被っていない文字を指定する必要があります。

9
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
10