IE关闭有flash的页面js报错

IE关闭有flash的页面,js脚本报错,直接在IE里也没有报错,在用C++开发的桌面软件中使用了IE控件,浏览时才会出现这种情况,而且如果flash是本来就写在页面里的,也没问题,如果是后创建元素加到页面就有问题,比如用jquery的get方法取到html文本再append到页面上div里就有问题。可以确定是调用flash上开放的js方法出了问题,但是不知道是哪调的。结果找到 这个页面,讲Flash ExternalInterface的问题。
关闭的问题:
引用
Internet Explorer Page Unload Bug
If you override the __flash__addCallback method (or are using Flash in an untraditional scenario like inside of a Microsoft Behavior), you can sometimes get exceptions when the page unloads on Internet Explorer. The source of this is the __flash__removeCallback method getting a null exception, which gets called as a page is unloaded. You can fix this by overriding this method and adding a better null check:

window.__flash__removeCallback =
   (function() {
      return function(instance, name) {
         if (instance) instance[name] = null;
      }; // IE 6 dangling semicolon needed
   )(); // force another closure to prevent IE memory leaks
Note that you should define this function after the Flash plugin has loaded, perhaps in a onDOMContentLoaded function. Otherwise Flash will overwrite your workaround with the original, faulty function.

以前遇到过调用的问题,后来用LocalConnection解决的,现在怀疑是不是下边的问题:
引用
Using Inside a Microsoft Behavior
If you are using a Microsoft Behavior in order to extend Internet Explorer's layout engine with JavaScript?, perhaps having the Flash object be 'hidden' from the external DOM using the ViewLink trick so developers don't see it but rather your new, custom tag instead (such as an SVG root element tag), ExternalInterface won't work correctly initially and your calls won't work.

The way to fix this is to get a reference to your Flash object first ('hiding' elements inside a Microsoft Behavior is detailed here); then simply have a variation of the method defined above in the Performance section to make your Flash methods callable; the only difference is we leave the eval() function in:

function makeCallable: function(flashObj, methodName) {
   // if we use the Behavior ViewLink trick to 'hide' the Flash object
   // from the external page's DOM (see FlashInserter._insertFlashIE for
   // the SCRIPT embedType), then Flash's ExternalInterface
   // doesn't work correctly.
   flashObj[methodName] =
      (function(methodName) {
         return function() {
            eval(this.CallFunction(
               '<invoke name="' + methodName + '" returntype="javascript">'
                  + __flash__argumentsToXML(arguments, 0)
               + '</invoke>'));
         }; // dangling semi-colon for IE 6
      })(methodName); // force re-closure to prevent IE memory leaks
}
If you do this, you will most certainly want to follow the instructions in "Internet Explorer Page Unload Bug" above as well.

里边还讲到:When you add a callback using ExternalInterface, that method actually internally uses eval() in order to turn strings into objects.利用这一点在有些时候可以提升调用的性能。

你可能感兴趣的:(JavaScript,jquery,Microsoft,IE,Flash)