在Windows Phone 8中检测web浏览器页面的底部
本文关键字:浏览器 底部 web 检测 Windows Phone | 更新日期: 2023-09-27 18:11:59
我有一个使用浏览器控件的xaml页面。我需要向下滚动到网页,一旦到达底部,我必须启用一个按钮。
提前感谢!
这有两个部分。第一个是在Javascript中检测浏览器到达页面底部的时刻。第二种是将事件转发给c#代码。
假设您要求WebBrowser
控件导航到给定的页面。首先,在c#代码中,订阅Navigated
事件以注入适当的Javascript代码:
private void WebBrowser_Navigated(object sender, NavigationEventArgs e)
{
const string Script = @"window.onscroll = function() {
if ((window.innerHeight + document.documentElement.scrollTop) >= document.body.offsetHeight) {
window.external.notify('bottom');
}
};";
this.WebBrowser.InvokeScript("eval", Script);
}
这个Javascript代码使用window.external.notify
方法通知c#代码。要接收通知,您需要订阅WebBrowser
的ScriptNotify
事件:
private void WebBrowser_ScriptNotify(object sender, NotifyEventArgs e)
{
if (e.Value == "bottom")
{
// Reached the bottom of the page
}
}