加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 在WebBrowser控件中,window.external不可用

发布时间:2020-12-15 21:26:25 所属栏目:百科 来源:网络整理
导读:我想在WebBrowser控件中调用C#方法.以下是我的代码: 在XAML中, phone:WebBrowser Margin="0,0" Name="WebBrowserForDetails" VerticalAlignment="Top" Height="300" ScriptNotify="WebBrowserForDetails_ScriptNotify" IsScriptEnabled="True" / 在C#中, pr
我想在WebBrowser控件中调用C#方法.以下是我的代码:

在XAML中,

<phone:WebBrowser Margin="0,0" Name="WebBrowserForDetails" VerticalAlignment="Top" Height="300" ScriptNotify="WebBrowserForDetails_ScriptNotify" IsScriptEnabled="True" />

在C#中,

protected override void OnNavigatedTo(NavigationEventArgs e)
{

    string html = string.Format("<html><head><title></title><script type="text/javascript">{0}</script></head><body><button onclick="call();">Push</button>","function call(){ window.external.notify(123) ;}");
    WebBrowserForDetails.NavigateToString(html);
}

private void WebBrowserForDetails_ScriptNotify(Object sender,NotifyEventArgs e)
{
    Debug.WriteLine(e.Value);
}

预计在调试窗口中看到123.

当< button> Push< / button>被推,window.external.notify永远不会被调用.实际上,window.external不可用.我想从WebBrowser控件调用window.external.notify函数来调用WebBrowserForDetails_ScriptNotify方法.我该怎么办?

编辑

参考链接:MSDN: window.external.notify,Any way to set the WP7 Webbrowser control height Dynamically and lock scrolling?和Displaying HTML Content in Windows Phone 7

解决方法

你的代码看似正确,但window.external.notify()方法是String参数,而不是Integer.请尝试使用window.external.notify(‘123’)调用. 希望这可以帮助.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读