为 Windows Phone 8 App WebBrowser Control 注册自定义协议

编程入门 行业动态 更新时间:2024-10-28 11:25:15
本文介绍了为 Windows Phone 8 App WebBrowser Control 注册自定义协议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在寻找一种为 Windows Phone 8 注册自定义协议的方法.我尝试使用 WebRequest.RegisterPrefix("xxx://", this) 注册自定义协议,但是这个不适用于 WebBrowser 控件.由于我们的协议方案没有有效的 uri,如果应用尝试导航(通过 location.url='xxx://this-is-no-valid-uri'),它就会崩溃.

I'm searching for a way to register a custom protocol for Windows Phone 8. I tried to register a custom protocol with WebRequest.RegisterPrefix("xxx://", this) but this will not work for the WebBrowser control. Since our protocol scheme is no valid uri the app will just crash if it try to navigate (via location.url='xxx://this-is-no-valid-uri').

我希望任何人都能在黑暗中传播光明;)

I hope anyone can spread light into the darkness ;)

这里是我的测试项目.我认为这是一个主要错误,因为您可以通过简单的 JavaScript 语句强制每个应用程序崩溃.

Here is my test project. I think this is a major bug because you can force every app to crash with just a simple JavaScript statement.

推荐答案

我的问题终于有了解决方案,您需要注册一个自己的 UriParser.

I finally got a Solution for my Problem, you need to register a own UriParser.

我的 UriParser:

public class MyUriParser : UriParser
{
    public MyUriParser()
    {

    }

    protected override string GetComponents(Uri uri, UriComponents components, UriFormat format)
    {
        return "";
    }
    protected override bool IsWellFormedOriginalString(Uri uri)
    {
        return true;
    }
    protected override void InitializeAndValidate(Uri uri, out UriFormatException parsingError)
    {
        parsingError = null;
    }
    protected override bool IsBaseOf(Uri baseUri, Uri relativeUri)
    {
        return false;
    }
    protected override string Resolve(Uri baseUri, Uri relativeUri, out UriFormatException parsingError)
    {
        parsingError = null;
        return "";
    }
}

注册方式:

if (!UriParser.IsKnownScheme(SCHEMENAME_0))
    UriParser.Register(new MyUriParser(), SCHEMENAME_0, 80);

这篇关于为 Windows Phone 8 App WebBrowser Control 注册自定义协议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-26 17:05:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1139280.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   协议   Phone   Windows   App

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!