Answer the question
In order to leave comments, you need to log in
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
var url = window.location.href;
if(url.indexOf('www.test.ru/helloworld.action') != -1)
alert('Part of URL exist');
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 questionAsk a Question
731 491 924 answers to any question