Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
105
rated 0 times [  111] [ 6]  / answers: 1 / hits: 18451  / 12 Years ago, sat, may 26, 2012, 12:00:00

Displaying an image from a remote server:



<img src=http://remotehost/path/to/a.png alt=Image A />


However, if the current page is accessed via HTTPS, linking images via unencrypted HTTP will yield security warnings. While I could just specify https:// regardless of the current protocol, doing so would be wasteful since I really don't care to secure the transmission of this image unless it is necessary (when the visitor is using HTTPS).



Is it possible to specify a URL for the src attribute of the img tag such that the protocol in the URL is dynamically chosen based on the protocol used to access the current page? To illustrate what I mean:



<img src=(JavaScript's window.location.protocol)//remotehost/path/to/a.png alt=Image A />


What if we use JavaScript? We could give the img tag an id so that we can locate it and set the src to start with window.location.protocol.



Could also use base64 to bypass the HTTP/HTTPS problem altogether, but this isn't ideal for what I'm doing.



What can you guys recommend?


More From » html

 Answers
23

Just do :



<img src=//remotehost/path/to/a.png alt=Image A />

[#85336] Friday, May 25, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
grayson

Total Points: 36
Total Questions: 113
Total Answers: 95

Location: Tonga
Member since Fri, Aug 21, 2020
4 Years ago
grayson questions
;