[英]Yeoman Angular.js/Express.js - Grunt overwrites index.html on each manual restart
[英]condition to load only some script and not all in the index.html using angular.js
我将简短地评论我的问题。 我的发展很大,而且我注意到它不适用于Internet Explorer。 然后,如果用户从Internet Explorer进入,将不会加载产生错误的文件,而只会加载兼容且不会产生错误的文件。 这是我的逻辑,但是我不确定该怎么做。 如果我可以直接从纯JavaScript进行操作,我不感兴趣。 非常感谢你。
<script src='app/constantes.js'></script>
<script src='app/controllers.js'></script>
if(!internet explorer)
<script src='app/app.js'></script>
<script src='components/controllers/landing/landingController.js'></script>
<script src='components/controllers/reportes/reportesController.js'></script>
<script src='components/controllers/reportes/reportesReceptorController.js'></script>
<script src='components/controllers/contacto/contactoController.js'></script>
<script src='components/controllers/acerca/acercaController.js'></script>
<script src='components/controllers/loginController.js'></script>
<script src='components/controllers/page404/page404Controller.js'></script>
else
<script src='app/app_internetexplorer.js'></script>
<script src='components/controllers/incompatible/incompatibleController.js'></script>
我更喜欢的一种方法是创建script
标记,并根据您的条件将其动态注入DOM
,以下是所指的内容:-
使用window.navigator.userAgent
来确定browser
(在您的情况下是Internet Explorer)并在internet_explorer
对其进行初始化
您可以使用array
将所有js
文件保存在一个位置并loop
遍历,例如
var other_browser_scripts = ['app/app.js',
'components/controllers/landing/landingController.js',
'components/controllers/reportes/reportesController.js',
'components/controllers/reportes/reportesReceptorController.js',
'components/controllers/contacto/contactoController.js',
'components/controllers/acerca/acercaController.js',
'components/controllers/loginController.js',
'components/controllers/page404/page404Controller.js'],
internet_explorer_scripts = ['app/app_internetexplorer.js',
'components/controllers/incompatible/incompatibleController.js'];
var head = document.getElementsByTagName('head')[0];
var js = document.createElement("script");
js.type = "text/javascript";
if(!internet_explorer)
{
for(var i = 0; i < other_browser_scripts.length; i++) {
js.src = other_browser_scripts[j];
dumpToDOM();
}
}
else
{
for(var j = 0; j < internet_explorer_scripts; j++) {
js.src = internet_explorer_scripts[j];
dumpToDOM();
}
function dumpToDOM(){
head.appendChild(js);
js = document.createElement("script");
js.type = "text/javascript";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.