Downloading an image using XMLHttpRequest in a userscript

前端 未结 4 2181
走了就别回头了
走了就别回头了 2020-12-05 05:34

First of all there is a question with the same title here on SO but its not what I\'m looking for and it doesn\'t have a complete answer either.

So here\'s my questi

4条回答
  •  北海茫月
    2020-12-05 06:16

    Krof Drakula is right, you cannot load an image from a different domain, but do you really need to do this? You can create and append an img tag and wait for it to load (with something like jQuery load()).

    var img = document.createElement( 'img' );
    img.setAttribute( 'src', url );
    document.getElementsByTagName('body')[0].appendChild( img );
    

提交回复
热议问题