locked
Share Target - retrieve all images from a web page

    Question

  • Does anyone know if it is possible to retrieve all images from a webpage when you app is a share target? The only way I can think of, is retrieving a url from a share target, then making another WinJS.xhr request similar to 

      WinJS.xhr({ url: "http://www.example.com" })
                    .done(function complete(result) {
                        // Report download.
                        var foo= toStaticHTML(result.response);
               var images = foo.match(/<img([^>]*)/gi);
                    });

    and using regex to pull out the img tags. This seems a bit cumbersome to me, but if I share a website (bearing in mind I probably do not own it) all I get are small images that are no good to me. I want a user to be able to choose what image, out of all the available images on a page they want to use

    The issues with the above approach are that it still throws errors based on scripts that are trying to execute on example.com, even though I've used the toStaticHTML method. (I guess it's a consequence of the request in the background as the script tags are stripped in 'foo')

    thanks
    • Edited by TommyBs Thursday, June 13, 2013 12:05 PM
    Thursday, June 13, 2013 12:04 PM

Answers

  • That's essentially what you have to do unless the share source included the images on a resource map to go along with an HTML page in the DataPackage. Your toStaticHtml call affects the behavior on the client only. Any server side code has already run on the server before the xhr call completes.

    Friday, June 14, 2013 6:45 AM
    Moderator