【发布时间】:2012-02-29 13:41:54
【问题描述】:
一段时间以来,这一直是我团队中的一个常见问题。显然没有原因,IE8 有时只加载脚本。我正在使用 asp.net mvc3 并且一些脚本是通过 _layout.cshtml 加载的(这就像我所有其他页面都继承的母版页)。其他一堆脚本仅在需要时加载。我必须提到我开始使用 Head.js 来加载我的脚本。我其实希望它能解决 IE8 脚本加载问题。
这些问题不会出现在 firefox 或 chrome 上(这是另一个动机,我确信它只发生在 IE 上)。看起来,如果单个脚本在 IE8 上中断,则此中断会通过其他脚本传播。
我知道这可能是一个过于宽泛的问题,仅凭上述情况无法解决。所以我想知道的是你有过这样的问题吗?如果是,你是怎么解决的?我非常感谢一些指导,因为我必须使用 IE。
这里是在 _layout.cshtml 上加载的脚本,按加载顺序:
- 头.js;
- jquery-1.5.1.min.js;
- modernizr-1.7.min.js;
- jquery-ui-1.8.11.min.js;
- jquery.ui.datepicker-pt-BR.js;
- jquery.validate.min.js;
- jquery.validate.unobtrusive.min.js;
这些是我在某些页面上使用的其他一些脚本(不按它们的顺序):
- jquery-blockUI.js;
- jquery.jqGrid-4.1.2.min.js;
- jquery.orbit-1.2.3.min.js;
- jquery.jqplot.min.js(以及其中一些渲染器);
- jquery.form.wizard-min.js;
- ZeroClipboard.js;
编辑
作为 T.J.要求一些代码,因为仅使用所用脚本的名称很难识别问题,就在这里。
在 _layout.cshtml 上加载的脚本
<head>
<script src="@Url.Content("~/Scripts/head.min.js")" language="javascript" type="text/javascript"></script>
//Lots of css files loaded mostly through document.write
<script type="text/javascript" language="javascript">
// if (head.browser.mozilla || head.browser.webkit || head.browser.opera ||
// (head.browser.ie && (head.browser.version == '9.0'))) {
head.js('@Url.Content("~/Scripts/jquery-1.5.1.min.js")')
.js('@Url.Content("~/Scripts/modernizr-1.7.min.js")')
.js('@Url.Content("~/Scripts/jquery-ui-1.8.11.min.js")')
.js('@Url.Content("~/Scripts/jquery.ui.datepicker-pt-BR.js")')
.js('@Url.Content("~/Scripts/jquery.validate.min.js")')
.js('@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")');
if (screen.width == 1024) {
head.js('@Url.Content("~/Scripts/resolucao1024.js")');
} else {
head.js('@Url.Content("~/Scripts/resolucaoMaior1024.js")');
}
</script>
@RenderSection("Header", false)
</head>
在图表和图形页面上加载的脚本
@section Header{
<script type="text/javascript" language="javascript">
head
.js('@Url.Content("~/Scripts/jquery-blockUI.js")')
.js('@Url.Content("~/Scripts/jqGridMVC/grid.locale-pt-br.js")')
.js('@Url.Content("~/Scripts/jqGridMVC/jquery.jqGrid-4.1.2.min.js")')
.js('@Url.Content("~/Scripts/jquery-ConfigAjax.js")')
.js('@Url.Content("~/Scripts/jqPlot/jquery.jqplot.min.js")')
.js('@Url.Content("~/Scripts/jqPlot/jqplot.highlighter.min.js")')
.js('@Url.Content("~/Scripts/jqPlot/jqplot.dateAxisRenderer.min.js")')
.js('@Url.Content("~/Scripts/jqPlot/jqplot.pieRenderer.min.js")')
.js('@Url.Content("~/Scripts/jqPlot/jqplot.donutRenderer.min.js")')
.js('@Url.Content("~/Scripts/jqPlot/jqplot.cursor.min.js")');
</script>
}
编辑 2
哦!我忘了提到每次我调用一些 javascript 功能时,我都会使用 head(function() {}) 而不是 $(function(){})(建议在 head.js 网站上使用)。
编辑 3
正如 Zeta 所问,我提供了来自 IE 控制台的打印(来自我的图表和图形页面)。
因为我是巴西人,所以是葡萄牙语。不过很容易理解:这意味着 'jqplot' 为 null 或不是对象。 就像 jqplot 从未加载过或在加载过程中出现问题。
【问题讨论】:
-
请引用加载脚本的代码和标记。仅仅告诉我们它们是什么可能还不够。
-
这是在生产环境中发生还是在您使用 Visual Studio 开发服务器时发生?
-
我以前经常遇到这个问题。但它只发生在本地主机上。使用真实服务器一切正常。
-
-
@T.J.Crowder 我理解,但我之前提到过,如果这样做将是一个非常广泛的问题,因为我必须发布我称之为这些脚本的每一点。不管怎样,我会在我经常打电话给他们的地方发帖。
标签: javascript asp.net-mvc internet-explorer razor