How to display non-SSL images on HTTPS connection?

前端 未结 7 1035
耶瑟儿~
耶瑟儿~ 2020-12-28 15:32

On my https web site, how can I display images from a web site without a certificate?

I own the example domain of:

  • http://www.example.
7条回答
  •  暖寄归人
    2020-12-28 16:17

    To extend @Jaka Jančar's answer, do you NEED to download the images via AJAX? You can replace the AJAX call with this: add an IMG element dynamically.

    function load_image_instead_of_ajax_call(dom_parent_element,image_url) {
        var img = document.createElement('img');
        img.onload = your_success_callback_function;
        img.onerror = your_error_callback_function;
        img.src = image_url;
        dom_parent_element.appendChild(img);
    }
    

    This way, your image resource gets loaded, with a proper callback on success/error.

    Some browsers may complain that your page contains both http and https content, but it is not very common (this seems to be off by default in most browsers).

提交回复
热议问题