Mamdouh Winningstar
Mamdouh Winningstar

Reputation: 25

if current url doesn't contain location.search redirect to home

want to check if current url doesn't contains location.search do redirect to home before loading page

search page must have search location like : example.com/s/page.html?search=some+query

var home = "example.com",
searchpage="example.com/s/page.html";

check if current page url load

example.com/s/page.html

without ?search=some+query redirect to home

how to translate "doesn't contains" in javascript / jquery

 var search = window.location.search;
  if(window.location.href!=search) {
window.location.href=home;
});

I know that's wrong

hope to redirect before page load content

thanx alot in advance

Upvotes: 0

Views: 811

Answers (1)

Riad
Riad

Reputation: 3850

You can try this:

var curLocation= location.href;

if(curLocation.search("search") >= 0 ) {
     window.location.href=home;
};

JS FIDDLE

Upvotes: 1

Related Questions