0

I want to execute a javascript snippet that check whatever the browser supports angular or not. In the second case the script will do a redirect towards a static html webpage.

My intent is not rely on polyfills to support outdated browsers, but give a nice UX anyway by inviting the visitor to access my website with a modern browser.

Is it possible?

5
  • 3
    I don't see why not - put it in your index.html Commented Jul 31, 2021 at 17:32
  • 1
    Angular might already be booting then though. Your main.ts file might be a better spot.. Commented Jul 31, 2021 at 18:09
  • 1
    see stackoverflow.com/a/41779787 Commented Jul 31, 2021 at 18:12
  • @aviadP. wouldn't in that way be executed in each page of my angular app? Commented Jul 31, 2021 at 21:36
  • 1
    Angular is a SPA, so index.html is processed once, then all the view changes are performed in javascript Commented Jul 31, 2021 at 21:41

1 Answer 1

1

In your main.ts

//replace this
//    platformBrowserDynamic().bootstrapModule(AppModule)
//      .catch(err => console.error(err));

//by some like:

if (executeAjavaScriptFunction())
{
  platformBrowserDynamic().bootstrapModule(AppModule)
     .catch(error=>console.log(error))
}
else
{
  alert("improve your navigator");
}

Or you can also write in your .html some like

  <app-root>
   If you can't see the application visit www.myoldpage.com
  </app-root>
Sign up to request clarification or add additional context in comments.

1 Comment

But...if I wrote it inside of main.ts wouldn't I be forced to compile as es5 for it to be processed in IE? Moreover, wouldn't the compiler give me error if I used something like window.agent?

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.