How to Determine Your Browser in JavaScript and Redirect to a Different Page

Asked 1 years ago, Updated 1 years ago, 21 views

Is it possible to redirect further from the page where JavaScript determines the browser UA?
I'd like to sort the pages separately between non-compatible mobile phones and compatible mobile phones.

1. Jump to the page and first determine the UA
Redirect in 2.0 seconds (this way if A or this way if B)

Is it impossible without clicking?
I'm sorry that I can't understand your question.

javascript

2022-09-30 14:46

1 Answers

Yes, just skip to window.location.href.(Configure redirect to avoid loops.)
For example, to fly to various places on ja.stackoverflow.com

varua=navigator.userAgent;
if(ua.indexOf('iPhone')>0||ua.indexOf('iPod')>0||ua.indexOf('Android')>0&ua.indexOf('Mobile')>0){
    // When using a smartphone
    window.location.href="https://ja.stackoverflow.com/questions";

} else if(ua.indexOf('iPad')>0||ua.indexOf('Android')>0){
    // When using a tablet
    window.location.href="https://ja.stackoverflow.com/tags";
} else {
    //?
    window.location.href="https://ja.stackoverflow.com";
}


2022-09-30 14:46

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.