我想使用jquery替换页面的所有http到https。
我正在尝试这样做:
jQuery('a').each(function() {
var href = jQuery(this).attr('href');
if (href.indexOf('http:') > -1) {
href = href.replace('http:', 'https:');
jQuery(this).attr('href', href);
}
});,我想替换http: to https: on page load指南我该怎么做?
发布于 2014-09-23 13:16:15
您可以设置protocol属性:
$("a[href]").each(function(){
if( this.protocol === "http:")
this.protocol = "https:"
});发布于 2014-09-23 13:03:54
使用jQuery的attr不会获得完整的URL,而是输入的href值,它可能只是一个本地路径。试试这个..。
jQuery('a').each(function() {
this.href = this.href.replace("http:", "https:");
});使用this.href将得到一个绝对的URL,因此它总是以协议类型为前缀。
https://stackoverflow.com/questions/25995779
复制相似问题