0

how can i use javascript/jQuery to check if a URL contains a specific link/text.

for example :
A user browse to my site and his URL is : "http//www.mywebsite.com/userprofile/abc&from=home"

I have set a variable and its value is "http//www.mywebsite.com/userprofile/abc" , i want to know how to detect if "http//www.mywebsite.com/userprofile/abc" exist in the URL("http//www.mywebsite.com/userprofile/abc&from=home") then execute a function.

Thanks!

0

1 Answer 1

1
var urlToCheck = "http//www.mywebsite.com/userprofile/abc";

if (window.location.href.indexOf(urlToCheck) > -1) {
  executeAFunction();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.