locked
Saving images from WebView(Windows Phone WinAPI)

    Question

  • I'm currently creating a Windows Phone Web Browser and plan on making it universal so I decided to target Windows RT.

    After a while I encountered an issue and I don't even know how or where to start. I was wondering how I can get a context menu to display when I hold down an image in WebView and save it to storage. Is this possible?

    Wednesday, May 14, 2014 2:40 AM

All replies

  • You'll need to do that from html inside the WebView. You cannot do so from outside code.
    Wednesday, May 14, 2014 3:43 AM
    Owner
  • You'll need to do that from html inside the WebView. You cannot do so from outside code.

    okay thanks. how could I go about implementing this?
    Thursday, May 15, 2014 3:47 PM
  • At a very high level you'd have to implement the context menu in HTML/JS (I'm not sure offhand how, but it shouldn't be hard to find out) and when it's selected have the JavaScript call window.external.notify to pass the URL for the image out to the WebView.ScriptNotify event.

    --Rob

    Thursday, May 15, 2014 10:38 PM
    Owner
  • I should be able to figure out displaying the context menu. 

    I tried getting the url using 

                 string notifyJS = @"<script type='text/javascript' language='javascript'>
                                window.onload = function() {
                                    var links = document.getElementsByTagName('a');
                                    for(var i=0;i<links.length;i++) {
                                        links[i].onclick = function() {
                                            window.external.Notify(this.href);
                                        }
                                    }
                                }
                            </script>";

    and set a value in the script notified event

    TextBox.Text = e.Value;

    But have had no luck so far. Sorry I'm still in the learning stages of using javascript,C# and the new API that Windows introduced with Windows Phone 8.1. Guessing it'll definitely take time.

    Thursday, May 15, 2014 11:55 PM