对于我网站上的每种产品,我都有一个页面来宣传几本来自亚马逊的书。我使用AWSECommerceService从Web服务器查询到的书。我从亚马逊收到的XML包含书籍列表,其中包含诸如标题,价格,图像URL等信息。我使用这些信息生成我的网站页面。Amazon提供的图像URL都是HTTP,而我需要使用HTTPS协议发布它们,以避免在浏览器控制杆上警告页面访问者。只需更换HTTP与HTTPS不工作。
例:
http://ecx.images-amazon.com/images/I/51tD0SDNMeL.SX166.jpg =>确定
https://ecx.images-amazon.com/images/I/51tD0SDNMeL.SX166.jpg => ERR_CERT_COMMON_NAME_INVALID
有什么建议吗?
显然,Google Chrome中的属性document.styleSheets存在问题.添加新样式表后,不会更新该属性.要重现该问题,只需运行以下代码:
// Create the link element
var element = document.createElement("link");
element.setAttribute("rel", "stylesheet");
element.setAttribute("type", "text/css");
element.setAttribute("href", "external.css");
// Add the link element
console.log('Before add: ' + document.styleSheets.length);
document.getElementsByTagName("head")[0].appendChild(link);
console.log('After add: ' + document.styleSheets.length);
Run Code Online (Sandbox Code Playgroud)
在FireFox中运行时,控制台将显示如下内容:
Before add: 4
After add: 5
Run Code Online (Sandbox Code Playgroud)
在Chrome中运行时,控制台将显示如下内容:
Before add: 4
After add: 4
Run Code Online (Sandbox Code Playgroud)
有趣的是,以下代码在两个浏览器上都能正常工作(返回相同的结果):
console.log('Before add: ' + document.getElementsByTagName("head")[0].children);
document.getElementsByTagName("head")[0].appendChild(link);
console.log('After add: ' + document.getElementsByTagName("head")[0].children);
Run Code Online (Sandbox Code Playgroud)
这是一个错误还是我做错了什么?
我在编写和测试以下函数时发现了这个问题,以便将CSS文件动态添加到网页:
function requiresCSS( name ) {
var sheets = document.styleSheets;
for (var i = 0; i < sheets.length; i++) { …Run Code Online (Sandbox Code Playgroud)