workwise
workwise

Reputation: 1103

Loading an HTTPS image url that may redirect to HTTP

I am using a particular API, which has an image url convention like:

https://us.battle.net/static-render/us/illidan/249/96749817-avatar.jpg?alt=wow/static/images/2d/avatar/6-0.jpg

As per convention, the server will redirect to an alternate thumbnail if the exact image is not found. The problem is - when redirecting, the server redirects to http, even if original call is made via https. My page that makes use of these urls is using https, and I end up getting warnings whenever there is such a redirect.

Is there an easy way in javascript/html using which I can force the use of https urls even if server is redirecting to http? One option perhaps is to load via javascript and intercept the redirect, change the protocol to https, etc, but that looks a bit complex.

As test code, an html page with below code suffices (must be loaded over https to see the issue):

<html>
<head><title>Some title</title></head>
<body>
<img src='https://us.battle.net/static-render/us/illidan/249/96749817-avatar.jpg?alt=wow/static/images/2d/avatar/6-0.jpg'>
</body>
</html>

Note: The server behaviour might have changed since the question was first asked, but I am still leaving the code as is because it is sufficient to understand the issue.

Upvotes: 7

Views: 2743

Answers (1)

nipos
nipos

Reputation: 76

With javascript and HTML it won't work because Google Chrome blocks anything with http urls on secured sites.
If the alternate image is on your server,you can embed it using https.
If not,you need a PHP curl script which parses the http image and makes it available on a https url.

Upvotes: 2

Related Questions