我使用以下页面创建Pinterest配置文件小部件:https: //business.pinterest.com/en/widget-builder#do_embed_user
问题是,当窗口小部件显示图像时,使用非安全链接.我需要在安全页面上显示小部件,因此需要它们为https://
我有什么想法可以解决这个问题吗?
好吧,经过一番研究后,我做了一个相当激烈的黑客攻击来完成这项工作。Pintrest 确实提供 https 内容,只是由于某种原因他们没有将其包含在他们的 API 中。因此,我逐步浏览了 API,找到了为 API 创建的任何元素设置属性的属性设置器。
无论如何..这是小提琴: https: //jsfiddle.net/nanff007/1/(确保https)
这是执行魔法的代码......
这是一种解决方法/黑客或任何你想称之为的方法。它不会永远有效。它也可能不适用于所有国家/地区,因为 akamai URL 可能会发生变化。最好的选择是向 Pintrest 提出请求票。
(function() {
$('a[data-pin-do]').each(function () {
$(this).attr('data-pin-dont', $(this).attr('data-pin-do'));
$(this).removeAttr('data-pin-do');
});
var timer = setInterval(function () {
for (prop in window) {
if (prop.search(/^PIN_/) > -1 && typeof window[prop] != 'boolean') {
clearInterval(timer);
window[prop].f.set = function (el, att, string) {
if(att == 'src' && el.tagName.toLowerCase() == 'img') {
string = string.replace(/(^http:\/\/)/i, "https://s-");
}
if (typeof el[att] === 'string') {
el[att] = string;
} else {
el.setAttribute(att, string);
}
};
$('a[data-pin-dont]').each(function () {
$(this).attr('data-pin-do', $(this).attr('data-pin-dont'));
$(this).removeAttr('data-pin-dont');
});
window[prop].f.init();
break;
}
}
}, 100);
}());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
172 次 |
| 最近记录: |