我想使用JavaScript将http的每个实例更改为https。我怎样才能做到这一点?源代码是什么样的?

最佳答案

无论如何,我假设您追求的是标签中的内容,但可以很容易地将其推断给其他人:

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

关于javascript - 如何在源代码中使用JavaScript将每个http更改为https?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4329249/

10-16 08:30