Skip to content Skip to sidebar Skip to footer

Force Javascript To Load Additional Resources Over Https

I am using the Virtual Keyboard (Deprecated) from Google in my current project. Unfortunately it loads some additionale js-resources from an insecure source. Is there a way to forc

Solution 1:

Based on the answer to another question it seems possible to redefine the src property of a <script> element, which is used to load the javascript code for the swedisch keyboard. If you make sure the following code is executed before the new google.elements.keyboard.Keyboard call, the http will be replaced by https. From the network info in the chrome debug console, this indeed seems to load the keyboard settings over https.

Object.defineProperty(HTMLScriptElement.prototype, 'src', {
    get: function() {
        returnthis.getAttribute('src')
    },
    set: function(url) {
        var prefix = "http://";

        if (url.startsWith(prefix))
            url = "https://" + url.substr(prefix.length);

        console.log('being set: ' + url);
        this.setAttribute('src', url);
    }
});

Solution 2:

Just setup your script url like this and it will work!

<scriptsrc="//www.google.com/jsapi"></script>

This is the url relative protocol The type"javascript" part is not anymore necessary as it is taken as javascript if nothing is specified, so save space! MDN element script

Post a Comment for "Force Javascript To Load Additional Resources Over Https"