3

We are trying to make the angular 7 application work only in few specific list of browsers. And if the browser not falls in the list configured, we just need to show a simple HTML page, and stop any further processing. The following code has been added for this, and its working fine in those browsers (eg: IE 8) in which Angular is not supported by default. But when trying to replicate the same behaviour in modern browser (eg:Latest version of Opera) its showing the error page(browser not supported) and proceeding to the application Login page. How to prevent this. (we dont want the navigation to login page in these specific set of browsers). The below code goes in Index.html

 <script>
   //showing relevant code section only

    BrowserDetect.init();
    //supported browser with old version
    if (BrowserDetect.browser == "MS Edge" && BrowserDetect.version < 13 ||
      BrowserDetect.browser == "Chrome" && BrowserDetect.version < 45 ||
      BrowserDetect.browser == "Safari" && BrowserDetect.version < 10 ||
      BrowserDetect.browser == "Firefox" && BrowserDetect.version < 53
    ) {
      document.write("HTML for old version browsers go here");
    }
    //unsupported browser eg:Opera, IE etc..
    else if (BrowserDetect.browser !== "MS Edge" && BrowserDetect.browser !== "Firefox"
      && BrowserDetect.browser !== "Chrome" && BrowserDetect.browser !== "Safari") {
      document.write("HTML for unsupported browser goes here");
    **//issue: In latest version of Opera Browser the unsupported HTML is shown and the application is getting navigated to the Login screen.  How to prevent further angular application execution from this line**
    }
  </script>
2
  • How does you appRoutes look like? Commented Mar 4, 2019 at 9:52
  • I need this to be done, even before angular app initialization. The old browsers wont execute the angular code itself. Commented Mar 4, 2019 at 9:54

1 Answer 1

2

Check main.ts file. In this file Angular bootstraps application.

It can be changed to something like this:

if (browserOk) {
    platformBrowserDynamic().bootstrapModule(AppModule);
} else {
    // browser unsupported
}
Sign up to request clarification or add additional context in comments.

5 Comments

How can we pass the browserOk variable from index.html to the main.ts file?
@amesh browserOk is just example, you can use BrowserDetect instead. Or use window object to hold value true/false window['browserOk'] = true/false.
I got its a variable given for example, but I'm worried about how we can pass the browser support information to maint.ts, so that we can prevent the app bootstrapping. And we need to synchronize the execution also.. right?
Use window object to pass browser information to main.ts. Browser detection code executes before main.ts. I think there should not be a problem with synchronization.
Thanks for your Kind help. I will check and update this. +1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.