0

I have an android app. I want to redirect on clicking on an image. I tried using jquery but its not working please help.

This is the code:

$(document).ready(function (){
  $(".add").click(function(){
     window.navigate("https://someurl/");
  });
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a class="add" href="https:someurl" class="imgcenter">
    <img class="add" src="ad_v2.jpg"/>
</a>
SONGSTER
  • 585
  • 3
  • 11
  • 28

5 Answers5

0

Try window.location= instead.

window.location = "https://someurl.com"
Alex Antonov
  • 14,134
  • 7
  • 65
  • 142
0

Did you try this variant window.location.href = "http://example.com/new_url";

Pe4eN
  • 44
  • 5
0

window.navigate is not supported by most browsers. Have a look here.

You should use window.location or window.location.replace() according to your needs. You can find a good explanation here.

Jamaslab
  • 61
  • 6
0

Use window.location = "http://...";. I've been coding cross-browser JavaScript for a few years, and I've never experienced problems using this approach.

window.navigate and window.location.href seems a bit odd to me.

P.S : .navigate() only works in IE.

Anant Dabhi
  • 10,864
  • 3
  • 31
  • 49
0

window.navigate is NOT supported cross browsers, you can try location.href or window.location.href

<a class="add" href="javascript: void(0)" class="imgcenter"><img src="ad_v2.jpg"/></a>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$(document).ready(function (){
  $(".add").click(function(e){
      e.preventDefault(); // Prevent multiple redirection
      location.href = "https://example.com/";
  });
});
</script>
Rahul K
  • 413
  • 3
  • 11