apply downloaded CSS on windows 8 metroUI app

时间秒杀一切 提交于 2019-12-13 06:04:52

问题


I have to download CSS file and apply style sheet to my app. I downloaded this file at the local folder and referenced it as

style.href = "ms-appdata:///local/css//custom.css"; 

and appended to head as

document.getElementsByTagName('head')[0].appendChild(style);  

after document onready event. Seems it has no effect (but I can see this element in the dom browser).

So is there any restriction for css source: app package, local folder? May be this impossible to reference downloaded CSS due to MS limitations? Or may be I'm doing something wrong? Any suggestions?


回答1:


Do keep in mind, however, that you can access the document.styleSheets collection and list, add, or remove CSS rules dynamically from JavaScript. You can access the individual rules themselves through the DOM using statements like document.styleSheets[0].cssRules[0].style.color = "red" or you if you've fetched yourself some custom CSS text (dynamically from your other CSS file online) you can add its styles to one of your active style sheets using something like document.styleSheets[0].cssText = "{my CSS code}". Do be sure that you're manipulating the right style sheet by checking the document.styleSheets[0].href.




回答2:


I think you're out of luck trying to head down that path.

Note that, for security reasons, you cannot navigate to HTML you have downloaded to this location and you cannot run any executable or potentially executable code, such as script or CSS.

Source: http://msdn.microsoft.com/en-us/library/windows/apps/hh781215

Also, this blog post seems possibly helpful: http://palermo4.com/post/How-to-Use-IFrames-in-WinRT-Apps.aspx



来源:https://stackoverflow.com/questions/17210798/apply-downloaded-css-on-windows-8-metroui-app

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