2

我的 WP 博客上安装了一个 Instagram 小部件。该博客具有 SSL,每次从“ http://distilleryimage6.s3.amazonaws.com ”显示图像时都会引发错误。由于在任何地方都找不到它,如何在小部件 .JS 代码中将“http”更改为“https”?

我尝试添加“https_shot=shot.replace("http","https");" 但这不起作用,因为它不是字符串...

感谢您提供的任何帮助。

代码:

if (o.social_network == "instagram") { 
    html = "";

    if (o.shape == "none") {
        html += '<div class="portfolio-grid"><ul id="thumbs">'
    } else {
        html += '<div class="portfolio-grid"><ul id="thumbs" class="shaped ' + o.shape + '">'
    }

    var token = "111111111111111111111111111111111111111";                      

    url =  "https://api.instagram.com/v1/users/search?q=" + o.user + "&access_token=" + token + "&count=10&callback=?";

    $.getJSON(url, function(data) {

        $.each(data.data, function(i,shot) {
            var instagram_username = shot.username;

            if (instagram_username == o.user) {
                var user_id = shot.id;

                if (user_id != "") {    
                    url =  "https://api.instagram.com/v1/users/" + user_id + "/media/recent/?access_token=" + token + "&count=" + o.limit + "&callback=?";

                    $.getJSON(url, function(data) {
                        $.each(data.data, function(i,shot) {

                            if (o.shape == "none") {
                                html += '<li class="item col' + o.columns + '">';
                            } else {
                                html += '<li class="item">';
                            }

                            var img_src = shot.images.standard_resolution.url;
                            var img_src_o = shot.images.standard_resolution.url;
                            var img_url = shot.link;
                            var img_title = "";

                            if (shot.caption != null) {
                                img_title = shot.caption.text;
                            }

                            if (o.shape == "none") {
                                html += "<img width='100%' src='" + img_src + "' alt=''><div class='item-info col" + o.columns + "'><h3 class='title'><a target='_blank' href='" + img_url + "' title='" + img_title + "'>"+ img_title + "</a></h3></div>";

                                html += '<div class="item-info-overlay"><div><a href="' + img_url + '" class="view">details</a><a title="' + img_title + '" href="' + img_src_o + '" class="preview" data-rel="prettyPhoto[]">preview</a></div> </div><!--END ITEM-INFO-OVERLAY-->';

                            } else {
                                html +=  "<div class='item-container'><img src='" + img_src + "' alt='' style='height:auto'></div>";

                                html += '<div class="item-info-overlay"><div><h3 class="title"><a target="_blank" href="' + img_url + '" title="' + img_title + '">'+ img_title + '</a></h3><a href="' + img_url + '" class="view">details</a><a title="' + img_title + '" href="' + img_src_o + '" class="preview" data-rel="prettyPhoto[]">preview</a></div>  </div><!--END ITEM-INFO-OVERLAY-->';                                                

                            }

                            html += "</li>";
                        });

                        html += "</ul></div>";
                        obj.append(html);
                        obj.removeClass("photostream");
                    });
                }
            }
        });
    });                 
}
4

1 回答 1

3

实际上,images对象内的所有 URL都是字符串.replace(),因此您可以简单地在变量声明的末尾调用一个方法:

var img_src = shot.images.standard_resolution.url.replace('http://', '//');
var img_src_o = shot.images.standard_resolution.url.replace('http://', '//');

这会将绝对 URL 替换为继承页面协议的 URL。因此,如果该页面使用 https,那么 URL 也将如此。

于 2013-05-08T17:15:19.193 回答