1

我正在使用 Worklight 5.0.6 开发应用程序。该应用程序面向平板电脑(iOS、Android 和 Windows)。该应用程序在 iOS 和 Android 上运行良好,但我无法让它在 Windows 8 上正常运行。当我单击链接时,该应用程序崩溃。这是错误消息的一部分:

"HTML1701: Unable to add dynamic content '  <link/><table></table><a href='/a'>a</a><input type='checkbox'/>'. A script attempted to inject dynamic content or elements previously modified dynamically that might be unsafe. For example, using the innerHTML property to add script or malformed HTML will generate this exception. Use the toStaticHTML method to filter dynamic content or explicitly create elements and attributes with a method such as createElement. For more information, see http://go.microsoft.com/fwlink/?LinkID=247104."

该应用程序应该在单击链接时注入一个 html 片段。我正在使用以下函数将 html 注入到元素中:

function loadPartial(path, elementId)
{
    $.get(path, function (data) {
        $(elementId).html(data).trigger("create");
        $("#my-navbar > ul").removeClass("ui-grid-a");
        if (!hideDuringFocus)
        {
            $("[data-role=header]").fixedtoolbar({ hideDuringFocus: "" });
            $("[data-role=footer]").fixedtoolbar({ hideDuringFocus: "" });
        }
    });
}

function loadPartialWithFunction(path, elementId, aFunction)
{
    $.get(path, function (data) {
        $(elementId).html(data).trigger("create");
        $("#my-navbar > ul").removeClass("ui-grid-a");
        if (!hideDuringFocus)
        {
            $("[data-role=header]").fixedtoolbar({ hideDuringFocus: "" });
            $("[data-role=footer]").fixedtoolbar({ hideDuringFocus: "" });
        }
        aFunction();
        });
} 

我在代码中犯了错误吗?任何帮助,将不胜感激。如果需要更多信息或源代码,请告诉我。

4

2 回答 2

2

问题已解决,谢谢。我必须用 MSApp.execUnsafeLocalFunction 包装代码,所以它看起来像这样:

function loadPartialWithFunction(path, elementId, aFunction)
{
    $.get(path, function (data) {
        MSApp.execUnsafeLocalFunction(function(){
            $(elementId).html(data).trigger("create");
            $("#my-navbar > ul").removeClass("ui-grid-a");
            if (!hideDuringFocus)
            {
                $("[data-role=header]").fixedtoolbar({ hideDuringFocus: "" });
                $("[data-role=footer]").fixedtoolbar({ hideDuringFocus: "" });
            }
            aFunction();
       });
    });
}  
于 2013-06-26T03:26:41.430 回答
1

这是 Win8 Metro 上的 jQuery 的一个问题。Metro 应用程序具有动态内容限制,需要首先绕过这些限制。这是一个堆栈溢出问题,对此问题有很多答案:

将 jQuery 与 Windows 8 Metro JavaScript App 一起使用会导致安全错误

于 2013-06-25T14:30:47.163 回答