Question

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.

Was it helpful?

Solution 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.

OTHER TIPS

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;
});
});
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top