首页 / C# / 使用InvokeScript更改C#变量
使用InvokeScript更改C#变量
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了使用InvokeScript更改C#变量,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1891字,纯文字阅读大概需要3分钟。
内容图文
我需要检查我的Windows Phone应用程序中的WebBrowser控件是否有历史记录,以及我弄清楚如何操作的方式是使用browser.InvokeScript(“eval”,“if(history.length> 0){ history.go(-1)}“);我需要使用这个或其他方法来设置变量,这样我只有在WebBrowser有历史记录时才能触发函数.我无法弄清楚如何设置它.
我正在使用的完整代码是:
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
var hasHistory = true;
browser.InvokeScript("eval", "if(history.length > 0){ history.go(-1) }");
if (AppSettings.Default.ExitWarning)
{
if (!hasHistory) {
if (MessageBox.Show("Are you sure you want to exit?", "Exit?", MessageBoxButton.OKCancel) != MessageBoxResult.OK)
{
e.Cancel = true;
}
}
}
}
解决方法:
我担心你的方法有缺陷! history.length值不能用于表示您所在的页面.如果您向前导航然后返回,则历史长度将为2以允许向前导航.
我通过跟踪C#代码中的导航来解决这个问题:
/// <summary>
/// Handles the back-button for a PhoneGap application. When the back-button
/// is pressed, the browser history is navigated. If no history is present,
/// the application will exit.
/// </summary>
public class BackButtonHandler
{
private int _browserHistoryLength = 0;
private PGView _phoneGapView;
public BackButtonHandler(PhoneApplicationPage page, PGView phoneGapView)
{
// subscribe to the hardware back-button
page.BackKeyPress += Page_BackKeyPress;
// handle navigation events
phoneGapView.Browser.Navigated += Browser_Navigated;
_phoneGapView = phoneGapView;
}
private void Browser_Navigated(object sender, NavigationEventArgs e)
{
if (e.NavigationMode == NavigationMode.New)
{
_browserHistoryLength++;
}
}
private void Page_BackKeyPress(object sender, CancelEventArgs e)
{
if (_browserHistoryLength > 1)
{
_phoneGapView.Browser.InvokeScript("eval", "history.go(-1)");
_browserHistoryLength -= 2;
e.Cancel = true;
}
}
}
如本博客文章所述:
http://www.scottlogic.co.uk/blog/colin/2011/12/a-simple-multi-page-windows-phone-7-phonegap-example/
内容总结
以上是互联网集市为您收集整理的使用InvokeScript更改C#变量全部内容,希望文章能够帮你解决使用InvokeScript更改C#变量所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。