动态加载jQuery mobile会导致IE最小化

Ale*_*pin 6 javascript debugging jquery internet-explorer jquery-mobile

好的,这是迄今为止我遇到过的最奇怪的错误.这很简单.如果我在任何版本的Internet Explorer中动态加载jQuery然后jQuery mobile,实际的IE窗口最小化.这通过IETester在IE的所有版本中发生,但是,如果我在IE9中运行完整版本,它会启动兼容模式,并且由于某种原因不会最小化.

我已经尝试了各种加载脚本的方法(在示例代码中注释),所有这些都导致了相同的行为.

为什么会这样?有办法解决吗?

http://jsfiddle.net/Xeon06/RCsuH/

jos*_*736 3

这是 jQuery mobile 中的一个已知问题。有问题的行是jquery.mobile.navigation.js:913

// Kill the keyboard.
// XXX_jblas: We need to stop crawling the entire document to kill focus. Instead,
//            we should be tracking focus with a live() handler so we already have
//            the element in hand at this point.
// Wrap this in a try/catch block since IE9 throw "Unspecified error" if document.activeElement
// is undefined when we are in an IFrame.
try {
    $( document.activeElement || "" ).add( "input:focus, textarea:focus, select:focus" ).blur();
} catch(e) {}
Run Code Online (Sandbox Code Playgroud)

有一个调用blur()将 IE 窗口发送到堆栈的末尾。

作为解决方法,您可以通过将脚本标记物理放置在<head>HTML 中来避免这种情况。

<!DOCTYPE HTML>
<html>
  <head>
    <link rel="stylesheet" href="http://code.jquery.com/mobile/latest/jquery.mobile.css" />
    <script src="http://code.jquery.com/jquery-1.6.2.js"></script>
    <script src="http://code.jquery.com/mobile/latest/jquery.mobile.js"></script>

...
Run Code Online (Sandbox Code Playgroud)

将脚本标签放置在文档中的其他位置或通过脚本插入它们会触发该错误。

这个小提琴演示了实际的解决方法。请注意,这仅适用于顶级文档。如果文档位于 中<iframe>,该错误仍然会出现。因此,如果你在 IE 7/8 中打开 JSFiddle 编辑器,它仍然会被发送到后面;但如果您只打开渲染的 HTML,则不会。