none
win8应用 自定义属性 报错 RRS feed

  • 问题

  • 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
    2014年2月13日 7:34

答案

  • HI,

    The error message actually gave you two options to work around the error:

    1. use toStaticHTML method to filter dynamic content
    2. 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/

    HOpe it can help you.


    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.

    2014年2月14日 5:27

全部回复

  • HI,

    The error message actually gave you two options to work around the error:

    1. use toStaticHTML method to filter dynamic content
    2. 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/

    HOpe it can help you.


    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.

    2014年2月14日 5:27
  • Thank you!
    2014年2月18日 5:53