I am in the process of implementing SSL on some of my wordpress-powered site\'s pages. Currently I\'m getting mixed content warnings on the secured pages - my custom theme inclu
I agree with the other posters who suggest that there are better ways to do what you are after. With that said, it sounds like you're in a bind, so let me offer a crack at it. (BTW, hat tip and a +1 vote to the protocol relative URL; I didn't know about that!)
Anyway, I assume what you are after is in tags, but it should be easy to extrapolate this to others:
if (document.location.protocol === 'https:') {
$('a').each(function() {
var href = $(this).attr('href');
if (href.indexOf('http:') > -1) {
href = href.replace('http:', 'https:');
$(this).attr('href', href);
}
});
}
With this help offered, I would encourage you to see if there's a safer / more practical way to do what you are trying to do. I will also mention that this approach will likely only work for links; modifying CSS and script references after the page loads will certainly backfire and not get you the result you want.
Notice the ":" in "document.location.protocol === 'https:'".