积极答复者
win8应用 自定义属性 报错

问题
-
HTML1701: 无法添加动态内容“<div class="" Privateattribute=“自定义属性”></div>”。脚本尝试插入了可能不安全的动态内容或以前经过动态修改的元素。例如,使用 innerHTML 属性添加脚本或格式错误的 HTML 将发生此异常。请使用 toStaticHTML 方法筛选动态内容,或使用诸如 createElement 等方法显式创建元素和属性。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=247104。
文件: about:blank
类似 $('<div class="" Privateattribute=“自定义属性”></div>');
在win8 js开发中 会报错 该怎么解决
是不是不能用自定义属性?
- 已编辑 mdnMS 2014年2月13日 7:38
答案
-
HI,
The error message actually gave you two options to work around the error:
- use toStaticHTML method to filter dynamic content
- explicitly create elements and attributes
Using toStaticHTML would look like this:
$('.some-element').append(toStaticHTML('<input type="radio" name="test"><label>Test</label>'));
But that will result in the HTML that gets created potentially looking different from the string you passed in; toStaticHTML will strip out elements and attributes that are considered unsafe.
The second option is to use the DOM APIs directly rather than jQuery to create the elements in question, you've already said that this is a no-go.
There is a third option, although it might not let you through the store verification process:
MSApp.execUnsafeLocalFunction(function() { $('.some-element').append('<input type="radio" name="test"><label>Test</label>'); });
Source from http://stackoverflow.com/questions/13139418/jquery-append-type-input-and-windows-store-app-html-css-js
In addition, you can refer here
http://davevoyles.azurewebsites.net/hacking-jquery-to-work-in-windows-8/
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.
- 已标记为答案 Pengzhen Song 2014年2月19日 10:44
全部回复
-
HI,
The error message actually gave you two options to work around the error:
- use toStaticHTML method to filter dynamic content
- explicitly create elements and attributes
Using toStaticHTML would look like this:
$('.some-element').append(toStaticHTML('<input type="radio" name="test"><label>Test</label>'));
But that will result in the HTML that gets created potentially looking different from the string you passed in; toStaticHTML will strip out elements and attributes that are considered unsafe.
The second option is to use the DOM APIs directly rather than jQuery to create the elements in question, you've already said that this is a no-go.
There is a third option, although it might not let you through the store verification process:
MSApp.execUnsafeLocalFunction(function() { $('.some-element').append('<input type="radio" name="test"><label>Test</label>'); });
Source from http://stackoverflow.com/questions/13139418/jquery-append-type-input-and-windows-store-app-html-css-js
In addition, you can refer here
http://davevoyles.azurewebsites.net/hacking-jquery-to-work-in-windows-8/
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.
- 已标记为答案 Pengzhen Song 2014年2月19日 10:44