1 回答

TA貢獻1789條經(jīng)驗 獲得超8個贊
我建議您嘗試在文件開頭添加下面的 polyfill index.js。
import 'react-app-polyfill/ie11';
import 'react-app-polyfill/stable';
如有必要,添加其他 polyfill。
在文件中添加IE 11開發(fā)。browserlistpackage.json
"browserslist": {
"production": [
"ie 11",
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"ie 11",
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
刪除.cache文件夾內(nèi)的node_modules文件夾,然后再次嘗試運行該應(yīng)用程序。
應(yīng)用程序應(yīng)在 IE 11 瀏覽器中加載。
之后嘗試使用下面的 JS 代碼并將其添加到您的 React 應(yīng)用程序中。
下面的代碼將使用用戶代理識別 IE 瀏覽器,您可以向用戶顯示有用的消息。
function detectIE() {
var ua = window.navigator.userAgent;
var msie = ua.indexOf('MSIE ');
if (msie > 0) {
return "IE " + parseInt( ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
}
var trident = ua.indexOf('Trident/');
if (trident > 0) {
var rv = ua.indexOf('rv:');
return "IE " + parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
}
// other browser
return "false";
}
var result=detectIE();
if (result=="false")
{
document.getElementById("info").innerHTML +="<h2>Welcome to the site...</h2>";
}
else
{
document.getElementById("info").innerHTML += "<h2>Dear user you are using " + result + " This browser is not supported by this site. Kindly use supported browser...</h2>";
}
此外,您可以根據(jù)自己的要求修改代碼示例。
添加回答
舉報