locked
Navigate a WebView to an image?

    Question

  • Matt,

    Building on you example, is a way to navigate to a graphic?  For example if my HTMLPage1.html file looked like:

    <!DOCTYPE html>
    <html>
    <head>
        <base target="_self">
        <title></title>
    </head>
    <body>
        <p><a target="_self" href="TestGraphic1.jpg">A Graphic</a></p>
    </body>
    </html>

    Where the TestGraphic1.jpg is local just the HTMLPage1.html.  I am only expecting to display the graphic (as is) in another html, the same html or some other container.

    Thanks,

    Doug

    p.s. if I change the target to _blank I get "no apps were installed to open this type of link".  I need my app to handle the graphic in this scenario but am stumped.

    Thursday, September 18, 2014 6:32 AM

All replies

  • I think you need to use WebView.NavigateToLocalStreamUri.  Please see http://blogs.msdn.com/b/wsdevsol/archive/2014/06/20/a-primer-on-webview-navigatetolocalstreamuri.aspx If it doesn't work, please let me know.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.


    Thursday, September 18, 2014 1:34 PM
    Moderator
  • This is a follow on of http://social.msdn.microsoft.com/Forums/windowsapps/en-US/76d58c0f-43e0-4848-a00e-c10071fb2492/is-base-targetblankselfparenttopframename-supported-by-webview-control-in-windows-rt-?forum=winappswithcsharp#316f6881-886a-41b2-ba80-1f2f2d7915b8 but when I replied to that forum My Profile shows I responded but my response doesn't show up.  So I've started a new thread!

    Building on Matt's solution, I am trying to navigate to a JPG (or any graphic):

    <!DOCTYPE html>
    <html>
    <head>
        <base target="_self">
        <title></title>
    </head>
    <body>
        <p><a target="_self" href="TestGraphic1.jpg">A Graphic</a></p>
    </body>
    </html>

    I have existing HTML documents (which exist in my apps appdata) that have this style of <a> tag embedded ad need to support the user clicking the graphic link which should display the "TestGraphi1.jpg" in its own container (WebView or other; the graphics are also internal to the appdata).  Since these types of <a> tags are embedded in internal (to the app) HTML content I need my C# app to handle it (which means I should have to register my app to handle JPG files).  When trying the above I just get a very small transparent (i.e. not even my graphic image is displayed) icon/image displayed.  What am I doing wrong?  How can I get the graphic to properly display?

    Thanks, swMercenary

    Thursday, September 18, 2014 6:46 PM
  • Matt,

    I currently use that approach to display local images which are tagged as "<img src=" (so your link does work for those).  However for "<a href=" links that have a non-html href link (e.g. a graphic, another file type) the approach doesn't work.  Once the page is loaded (and handled via the StreamUriWinRTResolver()) there's not other events that are raised (that I can see).  If you try my HTML sample (based on your previous sample) you see what I mean.

    Doug

    Thursday, September 18, 2014 6:55 PM
  • Doug - please post your specific project to OneDrive, and I'll check it out.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, October 3, 2014 4:57 PM
    Moderator
  • Matt,

    I've posted the project at: https://onedrive.live.com/redir?resid=2AA8FCFD13B99E3A%21128

    It does not implement StreamUriWinRTResolver() but if you click on any of the "A Graphic" links you'll see the issue.

    Doug

    Friday, November 7, 2014 12:12 AM
  • I see that the WebView does not want to load an image all by itself - can you embed the image inside a webpage? You might be able to get away with listening for the NavigationStarting event, determine if the link matches one of the image extensions (.jpg, etc) then wrap that call so that it loads that image inside an HTML page rather than an image itself.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, November 12, 2014 4:09 PM
    Moderator