I need to redirect in a javascript file to a given URI specified by the user.
So a quick example how I do this:
function redirect(uri) {
if(navigat
You can use match and replace in iOS but apparently not in Android. In my experience this is what works for redirects in Android:
<script type="text/javascript"> // <![CDATA[
if ( (navigator.userAgent.indexOf('Android') != -1) ) {
document.location = "http://www.your URL/your HTML file.html";
} // ]]>
</script>
You can just use: window.location = "http://example.com";
I would suggest :
location.assign('someUrl');
It's a better solution as it keeps history of the original document, so you can navigate to the previous webpage using back-button or history.back() as explained here.
Android supports document.location
without the href
property
Try to use:
function redirect(uri) {
if(navigator.userAgent.match(/Android/i))
document.location=uri;
else
window.location.replace(uri);
}
I think it should be window.location.href
, not document.location.href
.