Why does toStaticHTML remove data-* attributes

杀马特。学长 韩版系。学妹 提交于 2019-12-01 08:09:24

This is because of security concerns about inserting random bits of HTML into the document, and potentially allowing unsafe code to execute inside a protected context (your app, with full access to the WinRT, and users documents).

toStaticHtml is intended to remain 'secure' in the case of evolving HTML/web patterns so it is a whitelist rather than a blacklist.

Given your challenge that you have here I see the following options:

  • wrap the call to jquery in msExecUnsafeLocalFunction (see below). This means for the life of that call, all Dom insertions will be fine. This doesn't require a change to jquery, just your code.
  • Completely rewrite any of the DOM calls that Jquery is using under the covers to call with msExecUnsafeLocalFunction
  • Change the security context of your application to the web context rather than the local context. This, of course will lose you access to WinRT directly. You'll have to operate through some other mechanism (messaging between I frames or similar)
  • Use WinJS.Binding.Template to render your content rather than Jquery. This clones the nodes rather than stringifying the HTML
  • write your own node cloner
  • set the attribute with setAttribute after the safe node is inserted.

Example usage of msExecUnsafeLocalFunction:

MSApp.execUnsafeLocalFunction(function() {
    $('#container').html(html);
});

The data-role-attribute is not listed here: http://msdn.microsoft.com/en-us/library/windows/apps/hh465388.aspx

It's an unknown attribute and will be removed.

As mention in the docs data is not allowed: http://msdn.microsoft.com/en-us/library/windows/apps/hh465388.aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!