0

I am trying to redirect to url in jquery but it redirects on same page like when i try to redirect to this url- any.com it redirects to www.page.com/any.com

          setTimeout(function(){
               window.open(redirect_url);
              },2000);

any thoughts ?

Developer
  • 1
  • 5

2 Answers2

1

You should use window.location.href to redirect as

var redirect_url = "http://any.com";
setTimeout(function(){
     window.location.href = redirect_url;
},2000);

If your redirect_url doesn't have http/https protocol you should add it to redirect url as http://any.com instead of only any.com

Hien Nguyen
  • 24,551
  • 7
  • 52
  • 62
1

You can also try with your code, you missed only to add http:// before your url.

let redirect_url = 'http://www.page.com/any.com'
setTimeout(function(){
               window.open(redirect_url);
              },2000);
Codebrekers
  • 754
  • 1
  • 11
  • 29