N
N
Niko True2015-01-25 00:13:42
userscript
Niko True, 2015-01-25 00:13:42

JS how to check that part of url matches the one you need?

Hello,
the bottom line is this - I need to find out if the part of the domain on which I am located matches the one that I specify in the variable.
Suppose there is a link like www.test.ru/helloworld.action?dsdhkfjkdf&dfhjdfd=dfkjc. I start a variable in which I prescribe a part ( www.test.ru/helloworld.action), if the piece of the link that matches the variable in the variable is what I have in the address bar, then display an alert. Thanks in advance for your help. I read about window.location, but I didn’t guess how to do it with it.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Nalomenko, 2015-01-25
@buloshnik

var url = window.location.href;
if(url.indexOf('www.test.ru/helloworld.action') != -1)
  alert('Part of URL exist');

N
Niko True, 2015-01-26
@buloshnik

Sergei Nalomenko , can you tell me more then? How to stop the script? Those. I am filling out a form, but after submitting it, it just pops up. So, using your method - it is constantly sent to me, and I can’t understand how to interrupt it. I also tried loops, but to see something wrong somewhere, I tried to wrap it in one more if. Nothing helped.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question