2

I am looking to deny the use of IE for my reactjs application ... At the moment here is my App.js ... So i want to throw an error saying (IE is not allowed please use Chrome)

Any help greatly appreciated please

import React, { Component } from 'react';
import './App.css';
import { BrowserRouter as Router,
        Route,
        Link,
        Switch,
        Redirect
 } from 'react-router-dom';

class App extends Component {
  render() {
    return (
      <Router>
        <div>
          <Navbar />
        <Switch>
          <Route exact path="/" component={Home} />
          <Route exact path="/Home" component={Home} />
        </Switch>
        </div>
      </Router>
    );
  }
}

export default App;
dustybusty12
  • 107
  • 1
  • 7
  • 14

1 Answers1

1

This code will detect IE without worrying about someone messing with the UserAgent string:

if (window.MSCompatibleInfo != null) {
  alert('IE is not allowed please use Chrome!").
  throw new Error('IE is not allowed please use Chrome!');
}

The throw is to stop anything else from running

Intervalia
  • 10,248
  • 2
  • 30
  • 60
  • Put it where ever you want. You might want it at the top of your page and, instead of throwing an error, you could have it navigate to a different HTML page that would just display your message and not have any JavaScript. – Intervalia Mar 22 '19 at 17:51
  • Would you have any idea how i could get it to navigate to an error page ? i tried return render but cant get it to work – dustybusty12 Mar 24 '19 at 14:50
  • Sorry for the late reply. Change the `alert` to `location = ""`. But, be aware that is they have JS turned off then this won't work. Also, some browsers may prevent this from working thinking it is an injection attack. You may have to generate a simple page that has the error built in. You would hide the main page and show the error page. – Intervalia Jun 19 '20 at 14:19