if (location.protocol.indexOf('https') > -1) { var oMeta = document.createElement('meta'); oMeta.content = 'upgrade-insecure-requests'; oMeta.httpEquiv = 'Content-Security-Policy'; oMeta.id = 'httpsMeta'; document.getElementsByTagName('head')[0].appendChild(oMeta); }