EDIT: Why doesn't this work?

@match http://tumblr.com/*
$(document).ready(function() {
    $(img).each(function() {
        var i = $(this).attr("src");
        var n = i.replace("http://", "https://");
        $(this).attr("src", function() {
            return n;
        });
    });
});​

EDIT: To be clear, I DO NOT OWN THE WEBSITE. I want to have images on sites like https://facebook.com/ and https://tumblr.com/ be on https.

有帮助吗?

解决方案 2

The OP was really close, just need to tweak the selector: $(img) to $("img")

$(document).ready(function() {
        $("img").each(function() {
          var link = $(this).attr("src");
          var newLink = link.replace("http://example.com", "//example.com");
          $(this).attr("src", function() {
            return newLink
        });
     });
  });

jQuery requires the use of quotes around DOM element selectors, the OP script would throw img not defined.

其他提示

hey man it's so simple as far i can understand that you want! You want to change all images src?

$(document).ready( function() {
$("img").each( function() {
var i = $(this).attr("src");
var n = i.replace("http://", "https://");
$(this).attr("src", function() {
return n;
});
});
});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top