Web制作の時にページごと違う処理をさせたいこと、ありますよね?
そんな時にはURLやパスなどを取得して、そのページで処理をさせると思います。
今回はそれをご紹介いたします!
フローとしては
URL、パス取得
⬇︎
ページの判定
⬇︎
ページごとに処理を変える
といったものになります。
JavaScriptでページの判定をするときは基本的に「Location」オブジェクトを使用します。
実際のコード(取得したいもの一覧)
プロトコルを取得
location.protocol
ドメイン、ホストを取得
location.host
location.hostname
ポート番号を取得
location.port
ページのパスを取得
location.pathname
パラメーターを取得
location.search
ページ内リンクを取得
location.hash
これでURIを取得することができます。
このサイトでの一例
このサイトの記事一覧ページはこんな感じ。

そこで location.protocol をします。

「https:」が取得できました。
「SSL対応しているとき/していないとき」の判定に使えそうですね!
次は location.host、location.hostname をします。

「tashumist.com」が取得できました。
次に location.pathname をします。

「blog」が取得できました。
ページごとの処理ができるようになります。
次に location.search、 location.hash をします。

通常はパラメータやページ内リンクを取得できますが、ここではURIに記述がなかったため空文字になっています。
location.port も同様です。

なんとなく理解できましたでしょうか?
全てを画像で紹介!
パッと一目でわかるような図が自分でも欲しいと思ったので作成しました。
ぜひ参考にしてみてください!

コメント
[url=https://vsdoxycyclinev.com/]doxycycline 100mg tablets in canada[/url]
can i buy lasix from canada[/url]
best price cialis[/url]
buy cialis online with a prescription[/url]
kamagra rx review[/url]
cialis buy[/url]
cialis online no prescription[/url]
levitra with dapoxetine reviews[/url]
real propecia from canadian pharmacy[/url]
no prescription needed for levitra[/url]
india online pharmacy isotretinoin[/url]
Its not my first time to pay a visit this web page, i am visiting this web site dailly and obtain fastidious information from here all the time.
Thanks for your post. My partner and i have usually noticed that many people are
eager to lose weight simply because wish to appear slim and also attractive.
However, they do not often reaize that there are additional benefits to losijng weight also.
Doctors state that overweight people come acrross a variety of health
conditions that can be instantly attributed to their own excess weight.
Thankfully that people who’re overweight as well as suffering from various
disseases can reduce the sverity of their particular illnesses byy losing weight.
It is eazsy to see a continuous but notable improvemewnt in health
while even a bit of a amount of fat reduction is attained.
lasix with no scrpit[/url]
I do not know if it’s just me or if perhaps everyone else encountering issues with your blog.
It appears as if some of the written text within your posts are running off the screen. Can someone else
please comment and let me know if this is happening to them
as well? This might be a issue with my browser because I’ve had this happen before.
Cheers
It’s truly a nice and useful piece of information. I’m glad that you shared this helpful info with us.
Please keep us informed like this. Thanks for sharing.
moduretic
Its like you read my mind! You appear to grasp a
lot approximately this, such as you wrote the guide in it or something.
I think that you simply could do with a few % to force
the message home a bit, however other than that, this is excellent blog.
A great read. I will definitely be back.
Its such as you learn my thoughts! You appear to know
a lot about this, like you wrote the book in it or something.
I believe that you simply could do with a few percent to force the message house a little bit, however other than that, that
is great blog. A fantastic read. I will definitely be back.
My brother recommended I would possibly like this website.
He used to be entirely right. This post truly made my day.
You can not believe just how so much time I had spent for this info!
Thank you!
Definitely consider that which you stated. Your favourite justification seemed to
be at the internet the easiest factor to be aware of.
I say to you, I definitely get irked at the same time as other
people think about issues that they just do not recognize about.
You managed to hit the nail upon the top and outlined out the whole
thing without having side effect , people can take a signal.
Will likely be back to get more. Thanks
I just like the helpful information you supply to your
articles. I will bookmark your blog and check once more here regularly.
I’m reasonably sure I will be informed many new stuff right here!
Best of luck for the next!
order cialis
Unquestionably believe that that you said. Your favourite reason seemed to be on the internet the simplest thing to understand of.
I say to you, I certainly get annoyed while folks consider issues that they just don’t realize about.
You controlled to hit the nail upon the highest and outlined out the
whole thing with no need side effect , people can take a
signal. Will probably be again to get more. Thank you
cialis generic
Hello there! I simply wish to offer you a big thumbs up for
your great information you’ve got here on this post.
I will be coming back to your blog for more soon.
free local personals
[url=”http://onlinedatingtwo.com/?”]love and seek dating site[/url]
how do you do the keto diet https://ketodietplanus.com/
gay video dating games https://gaychatrooms.org/
gay dating discord https://gaychatus.com/
gay teens dating sites https://gaydatingzz.com/
bareback gay dating site https://gaychatgay.com/
mark perry gay dating scam https://freegaychatnew.com/
gay dating nj https://gayonlinedating.net/
gay bear dating site https://gayedating.com/
unlimited gay free dating site https://gay-singles-dating.com/
gay dating web site https://gaydatingcanada.com/
gay dating dc https://dating-gaym.com/
gay dating louisiana https://datinggayservices.com/
writing about yourself essay https://essayghostwriter.com/
write an analysis essay https://essaywritercentral.com/
custom writing essay https://essaypoints.com/
high school essay writing https://essaytag.com/
help with writing essays https://online2casino.com/
argumentative essay writing https://onlinecasinos4me.com/
free casino no deposit https://casinosonlinex.com/
casino online real money https://casinoonlinet.com/
free bonus no deposit https://casinoonlinek.com/
casino no deposit sign up bonus https://onlinecasinoad.com/
writing descriptive essays https://student-essay.com/
writing the essay nyu https://dollaressays.com/
exploring writing paragraphs and essays https://essaytodo.com/
sex games for parties https://sexgameszone.com/
my little pony sex porn games https://winsexgames.com/
college girls sex games https://sexgamesx.net/
survival sex games with forced incest https://sexygamess.com/
party sex games https://cybersexgames.net/
online casino free bet no deposit https://casinogamesmachines.com/
hard rock casino online https://conline-casinos-hub.com/
keto at starbucks https://ketogenicdiets.net/
cheap keto meals https://ketogendiet.net/
keto pizza near me https://ketogenicdietinfo.com/
keto net carbs https://ketogendiets.com/
write descriptive essay https://anenglishessay.com/
writing literary analysis essay https://topessayswriter.com/
write an argument essay https://yoursuperessay.com/
persuasive essay writing https://howtowriteessaytips.com/
writing a persuasive essay https://checkyouressay.com/
gay dating sims english tumblr https://gayprideusa.com/
chasabl gay dating https://gayfade.com/
older gay dating https://gaysugardaddydatingsites.com/
critical thinking and problem solving examples https://criticalthinkingbasics.com/
critical thinking strategies https://criticalthinkinginstitute.com/
winningham’s critical thinking cases in nursing https://criticalthinking2020.net/
critical thinking examples in nursing https://uncriticalthinking.com/
racial profiling essay https://choosevpn.net/
how to write a essay https://topvpndeals.net/
autobiography essay https://tjvpn.net/
what is essay format https://thebestvpnpro.com/
essay about myself https://vpn4home.com/
argumentative essay layout https://vpnshroud.com/
autobiography essay examples https://vpnsrank.com/
write a essay for me https://vpn4torrents.com/
njhs essay examples https://windowsvpns.com/
3deviation
3interlocutor
black gay dating sites https://gaypridee.com
victim met killer on gay dating site new yorlk https://gay-buddies.com
newest gay dating site https://gayprideusa.com
best dating website for gay man to pay for https://gaysugardaddydatingsites.com
gay smegma chat https://bjsgaychatroom.info/
young gay dating porn video https://gaypridee.com/
gay online video chat https://gaytgpost.com/
gay cam chat avenue https://gay-buddies.com/
gay dating websites for kids https://speedgaydate.com/
kitty glitter slots https://2-free-slots.com/
free vegas penny slots https://freeonlneslotmachine.com/
games slots https://candylandslotmachine.com/
hollywood slots in bangor https://pennyslotmachines.org/
aristocrat free slots https://slotmachinesworld.com/
free slots 1 https://slotmachinesforum.net/
argosy free fun slots https://slot-machine-sale.com/
free aristocrat slots https://beat-slot-machines.com/
scatter slots characters https://download-slot-machines.com/
slots of vegas casino https://411slotmachine.com/
wow equipment slots https://www-slotmachines.com/
konami slots https://slotmachinegameinfo.com/
dissertation prospectus example https://buydissertationhelp.com/
custom dissertation writing service 2019 https://dissertationwriting-service.com/
all but dissertation completion programs https://help-with-dissertations.com/
proposal and dissertation help objectives https://mydissertationwritinghelp.com/
uk dissertation writing help online https://dissertations-writing.org/
nursing dissertation help https://helpon-doctoral-dissertations.net/
Hmm is anyone else experiencing problems with the images on this blog loading?
I’m trying to determine if its a problem on my end or
if it’s the blog. Any responses would be greatly appreciated.