TanGio
TanGio

Reputation: 766

Loading both http and https for js scripts

I have an application, I can access them with http or https : http://www.test.com and https://www.test.com In the header of application I load an script for publicity : http://www6.smartadserver.com. If I access the application with http : the publicity are loaded. If I access the application with https, I get the error :

The page at htttps://www.test.com was loaded over HTTPS, but requested an insecure script http‍://www.smartadserver.com. This request has been blocked; the content must be served over HTTPS.

In the header of application I have :

<script src='http://www6.smartadserver.com/config.js?nwid=11111' type="text/javascript"></script>
<script type="text/javascript">
    sas.setup({ domain: 'http://www6.smartadserver.com', async: true, renderMode: 0, inSequence: true });
</script>

Can you help me please?

Upvotes: 2

Views: 1272

Answers (1)

Bogdan Burym
Bogdan Burym

Reputation: 5512

Try this way:

<script src='//www6.smartadserver.com/config.js?nwid=11111' type="text/javascript"></script>
<script type="text/javascript">
    sas.setup({ domain: '//www6.smartadserver.com', async: true, renderMode: 0, inSequence: true });
</script>

Section 4.2 of RFC 3986 provides for fully qualified URLs that omit protocol (the HTTP or HTTPS) altogether. When a URL’s protocol is omitted, the browser uses the underlying document’s protocol instead.

So, in usual words, you can avoid strictly setting protocol - and browser will select it automatically.

Upvotes: 3

Related Questions