2013-05-07 69 views
2

我有一个Instagram小工具安装在我的WP博客。每次从“http://distilleryimage6.s3.amazonaws.com”中显示图像时,该博客都会显示SSL并引发错误。我无法在任何地方找到它,我怎样才能在小部件.JS代码中将'http'更改为'https'?如何强制HTTPS URL头为Instagram amazonaws在Jquery托管图像

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

谢谢你的任何帮助,你可以鼓起。

CODE:

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"); 
        }); 
       } 
      } 
     }); 
    });     
} 

回答

3

其实,所有的images对象里面的网址都是字符串,所以你可以简单地在变量声明的末尾调用一个.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,那么网址也是如此。

+0

谢谢,我做了,但我仍然收到“https://blablabla.com/上的页面显示来自http://distilleryimage6.s3.amazonaws.com/blabla.jpg的不安全内容” – 2013-05-08 23:16:37

+0

闭嘴,我添加了('http://','https://'),它工作! – 2013-05-08 23:22:49

+0

太棒了!如果答案有帮助,请将其标记为已接受:)谢谢! – 2013-05-09 14:00:05