当前位置: 首页>>代码示例>>C#>>正文


C# UIWebView.EvaluateJavascript方法代码示例

本文整理汇总了C#中UIWebView.EvaluateJavascript方法的典型用法代码示例。如果您正苦于以下问题:C# UIWebView.EvaluateJavascript方法的具体用法?C# UIWebView.EvaluateJavascript怎么用?C# UIWebView.EvaluateJavascript使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UIWebView的用法示例。


在下文中一共展示了UIWebView.EvaluateJavascript方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HandleShouldStartLoad

        bool HandleShouldStartLoad(UIWebView webView, NSUrlRequest request, UIWebViewNavigationType navigationType)
        {
            // If the URL is not our own custom scheme, just let the webView load the URL as usual
            const string scheme = "hybrid:";

            if (request.Url.Scheme != scheme.Replace (":", ""))
                return true;

            // This handler will treat everything between the protocol and "?"
            // as the method name.  The querystring has all of the parameters.
            var resources = request.Url.ResourceSpecifier.Split ('?');
            var method = resources [0];
            var parameters = System.Web.HttpUtility.ParseQueryString (resources [1]);

            if (method == "UpdateLabel") {
                var textbox = parameters ["textbox"];

                // Add some text to our string here so that we know something
                // happened on the native part of the round trip.
                var prepended = string.Format ("C# says: {0}", textbox);

                // Build some javascript using the C#-modified result
                var js = string.Format ("SetLabelText('{0}');", prepended);

                webView.EvaluateJavascript (js);
            }

            return false;
        }
开发者ID:neurospeech,项目名称:app-core-ios,代码行数:29,代码来源:WebViewController.cs

示例2: FinishedLaunching

		//
		// This method is invoked when the application has loaded and is ready to run. In this 
		// method you should instantiate the window, load the UI into it and then make the window
		// visible.
		//
		// You have 17 seconds to return from this method, or iOS will terminate your application.
		//
		public override bool FinishedLaunching (UIApplication app, NSDictionary options)
		{
			JsBridge.EnableJsBridge();

			window = new UIWindow (UIScreen.MainScreen.Bounds);

			// get useragent
			UIWebView agentWebView = new UIWebView ();
			var userAgent = agentWebView.EvaluateJavascript ("navigator.userAgent");
			agentWebView = null;
			userAgent += " XamarinBarcodeSampleApp";

			// set default useragent
			NSDictionary dictionary = NSDictionary.FromObjectAndKey(NSObject.FromObject(userAgent), NSObject.FromObject("UserAgent"));
			NSUserDefaults.StandardUserDefaults.RegisterDefaults(dictionary);

			viewController = new Xamarin_iOS_BarcodeSampleViewController ();
			window.RootViewController = viewController;
			window.MakeKeyAndVisible ();

			viewController.MainWebView.LoadRequest(new NSUrlRequest(new NSUrl("http://xamarinbarcodesample.apphb.com/")));

			// listen for the event triggered by the browser.
			viewController.MainWebView.AddEventListener( "scanBarcode", delegate(FireEventData arg) {

				// show a native action sheet
				BeginInvokeOnMainThread (delegate { 
					//NOTE: On Android you MUST pass a Context into the Constructor!
					var scanningOptions = new ZXing.Mobile.MobileBarcodeScanningOptions();
					scanningOptions.PossibleFormats = new List<ZXing.BarcodeFormat>() { 
						ZXing.BarcodeFormat.All_1D
					};
					scanningOptions.TryInverted = true;
					scanningOptions.TryHarder = true;
					scanningOptions.AutoRotate = false;
					var scanner = new ZXing.Mobile.MobileBarcodeScanner();
					scanner.TopText = "Hold camera up to barcode to scan";
					scanner.BottomText = "Barcode will automatically scan";
					scanner.Scan(scanningOptions).ContinueWith(t => {   
						if (t.Result != null) {
							//Console.WriteLine("Scanned Barcode: " + t.Result.Text);

							// pass barcode back to browser.
							viewController.MainWebView.FireEvent( "scanComplete", new {
								code = t.Result.Text
							});
						}
					});
				});

			});
			
			return true;
		}
开发者ID:krishnanuj1990,项目名称:Xamarin.iOS.BarcodeSample,代码行数:61,代码来源:AppDelegate.cs

示例3: LoadingFinished

		public override void LoadingFinished(UIWebView webView)
		{
			if (webView.Request.Url.ToString().Equals(redirectUrl))
			{
				if (Listener != null)
				{
					Listener.OnPageStarted();
				}
				// iOS adds default HTML when it encounters JSON content.
				var content = webView.EvaluateJavascript("document.getElementsByTagName('pre')[0].innerHTML");
				var json = JObject.Parse(content);

				handler.Invoke(this, new CardVerificationResult { md = (string)json["MD"], paRes = (string)json["PaRes"] });
			}
		}
开发者ID:JudoPay,项目名称:Judo-Xamarin,代码行数:15,代码来源:Redirect3dSecureWebViewDelegate.cs

示例4: ViewDidLoad

		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

            View.BackgroundColor = UIColor.White;

            webView = new UIWebView((CGRect)View.Bounds);
		    webView.ShouldStartLoad = (wView, request, navType) =>
		    {
		        if (request == null)
		        {
		            return true;
		        }

		        string requestUrl = request.Url.ToString().ToLower();
                if (requestUrl.StartsWith(callback.ToLower()))
                {
                    callbackMethod(new AuthorizationResult(AuthorizationStatus.Success, request.Url.ToString()));
                    this.DismissViewController(true, null);
                    return false;
                }

                return true;
		    };

		    webView.LoadFinished += delegate
		    {
                // If the title is too long, iOS automatically truncates it and adds ...
                this.Title = webView.EvaluateJavascript(@"document.title") ?? "Sign in";
		    };

			View.AddSubview(webView);

            this.NavigationItem.LeftBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Cancel, this.CancelAuthentication);

			webView.LoadRequest (new NSUrlRequest (new NSUrl (this.url)));
			
			// if this is false, page will be 'zoomed in' to normal size
			//webView.ScalesPageToFit = true;
		}
开发者ID:varunpsr,项目名称:XamarinAzureAD,代码行数:40,代码来源:AuthenticationAgentUIViewController.cs

示例5: WebView

        public WebView(bool navigationToolbar, bool showPageAsTitle = false)
        {
            NavigationItem.BackBarButtonItem = new UIBarButtonItem() { Title = "" };
            Web = new UIWebView {ScalesPageToFit = true};
            Web.LoadFinished += OnLoadFinished;
            Web.LoadStarted += OnLoadStarted;
            Web.LoadError += OnLoadError;
            Web.ShouldStartLoad = (w, r, n) => ShouldStartLoad(r, n);

            if (showPageAsTitle)
            {
                Web.LoadFinished += (sender, e) =>
                {
                    Title = Web.EvaluateJavascript("document.title");
                };
            }

            _navigationToolbar = navigationToolbar;

            if (_navigationToolbar)
            {
                ToolbarItems = new [] {
                    (BackButton = new UIBarButtonItem(Theme.CurrentTheme.WebBackButton, UIBarButtonItemStyle.Plain, (s, e) => GoBack()) { Enabled = false }),
                    new UIBarButtonItem(UIBarButtonSystemItem.FixedSpace) { Width = 40f },
                    (ForwardButton = new UIBarButtonItem(Theme.CurrentTheme.WebFowardButton, UIBarButtonItemStyle.Plain, (s, e) => GoForward()) { Enabled = false }),
                    new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace),
                    (RefreshButton = new UIBarButtonItem(UIBarButtonSystemItem.Refresh, (s, e) => Refresh()))
                };

                BackButton.TintColor = Theme.CurrentTheme.WebButtonTint;
                ForwardButton.TintColor = Theme.CurrentTheme.WebButtonTint;
                RefreshButton.TintColor = Theme.CurrentTheme.WebButtonTint;

                BackButton.Enabled = false;
                ForwardButton.Enabled = false;
                RefreshButton.Enabled = false;
            }

            EdgesForExtendedLayout = UIRectEdge.None;
        }
开发者ID:rcaratchuk,项目名称:CodeFramework,代码行数:40,代码来源:WebView.cs

示例6: InnerCell

            public InnerCell(string reuseIdentifier, UITableView tableView)
                : base(UITableViewCellStyle.Default, reuseIdentifier)
            {
                _tableView = tableView;
                _webView = new UIWebView();
                _webView.ScrollView.Bounces = false;

                _webView.LoadFinished += delegate {
                    Console.WriteLine ("load finished");
                    string jsResult = _webView.EvaluateJavascript("document.body.scrollHeight;");

                    height = int.Parse(jsResult);

                    _tableView.ReloadData();
                };

                _webView.LoadError += delegate {
                    Console.WriteLine ("load error");
                };

                Add(_webView);
            }
开发者ID:jivkopetiov,项目名称:StackApp,代码行数:22,代码来源:WebViewRow.cs

示例7: ViewDidLoad

		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			this.NavigationItem.LeftBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Cancel, (x,y) => this.DismissViewController(true,null));
			this.webview = new UIWebView (this.View.Frame);
			webview.ShouldStartLoad = (webView, request, navType) => {return true;};
			webview.LoadFinished+= (object sender, EventArgs e) => {
				var payload = webview.EvaluateJavascript("document.title");
				Console.WriteLine(payload);
				if (payload.Contains ("Success payload="))
				{
					payload = Encoding.UTF8.GetString(Convert.FromBase64String( payload.Replace("Success payload=", String.Empty)));
					var rawToken = JsonConvert.DeserializeObject<Dictionary<string,string>>(payload);
					OnAuthenticationResponseArrived (new AuthenticationResponseEventArgs { Success = true, TokenInfo = rawToken });
					this.InvokeOnMainThread( ()=> (UIApplication.SharedApplication.Delegate.Window.RootViewController.DismissViewController(true, null))) ;
				}
				else if (payload.Contains ("Error message=")) {
					OnAuthenticationResponseArrived (new AuthenticationResponseEventArgs { Success = true, ErrorMessage = payload.Replace("Error message=", String.Empty) });
				}
			};
			this.View.AddSubview (webview);
			webview.LoadRequest (new NSUrlRequest (this.signInEndpoint));
		}
开发者ID:kidozen,项目名称:kido-xamarin,代码行数:23,代码来源:PassiveAuthViewController.cs

示例8: ViewDidLoad

        public override void ViewDidLoad()
        {
            //base.ViewDidLoad();

            var webFrame = new RectangleF (0, 0, this.View.Frame.Width, this.View.Frame.Height - 44);

            webView = new UIWebView (webFrame) {
                BackgroundColor = UIColor.White,
                ScalesPageToFit = true,
                AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight
            };

            webView.LoadStarted += delegate {
                UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true;
            };
            webView.LoadFinished += delegate {
                UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false;
                webView.EvaluateJavascript (script ());
            };

            this.View.AddSubview(webView);

            webView.LoadRequest(NSUrlRequest.FromUrl(new NSUrl(page.AbsoluteUri)));
        }
开发者ID:NotMyself,项目名称:BigRReader,代码行数:24,代码来源:PageViewController.cs

示例9: ViewDidLoad

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            View.BackgroundColor = UIColor.White;

            _webView = new UIWebView((CGRect) View.Bounds);
            _webView.ShouldStartLoad = (wView, request, navType) =>
            {
                if (request == null)
                {
                    return true;
                }

                string requestUrlString = request.Url.ToString();
                
                if (requestUrlString.StartsWith(BrokerConstants.BrowserExtPrefix, StringComparison.OrdinalIgnoreCase))
                {
                    DispatchQueue.MainQueue.DispatchAsync(() => CancelAuthentication(null, null));
                    requestUrlString = requestUrlString.Replace(BrokerConstants.BrowserExtPrefix, "https://");
                    DispatchQueue.MainQueue.DispatchAsync(
                        () => UIApplication.SharedApplication.OpenUrl(new NSUrl(requestUrlString)));
                    this.DismissViewController(true, null);
                    return false;
                }

                if (requestUrlString.ToLower(CultureInfo.InvariantCulture).StartsWith(_callback.ToLower(CultureInfo.InvariantCulture), StringComparison.OrdinalIgnoreCase) || requestUrlString.StartsWith(BrokerConstants.BrowserExtInstallPrefix, StringComparison.OrdinalIgnoreCase))
                {
                    callbackMethod(new AuthorizationResult(AuthorizationStatus.Success, request.Url.ToString()));
                    this.DismissViewController(true, null);
                    return false;
                }

                if (requestUrlString.StartsWith(BrokerConstants.DeviceAuthChallengeRedirect, StringComparison.CurrentCultureIgnoreCase))
                {
                    Uri uri = new Uri(requestUrlString);
                    string query = uri.Query;
                    if (query.StartsWith("?", StringComparison.OrdinalIgnoreCase))
                    {
                        query = query.Substring(1);
                    }

                    Dictionary<string, string> keyPair = EncodingHelper.ParseKeyValueList(query, '&', true, false, null);
                    string responseHeader = PlatformPlugin.DeviceAuthHelper.CreateDeviceAuthChallengeResponse(keyPair).Result;
                    
                    NSMutableUrlRequest newRequest = (NSMutableUrlRequest)request.MutableCopy();
                    newRequest.Url = new NSUrl(keyPair["SubmitUrl"]);
                    newRequest[BrokerConstants.ChallengeResponseHeader] = responseHeader;
                    wView.LoadRequest(newRequest);
                    return false;
                }
                
                if (!request.Url.AbsoluteString.Equals("about:blank", StringComparison.CurrentCultureIgnoreCase) && !request.Url.Scheme.Equals("https", StringComparison.CurrentCultureIgnoreCase))
                {
                    AuthorizationResult result = new AuthorizationResult(AuthorizationStatus.ErrorHttp);
                    result.Error = MsalError.NonHttpsRedirectNotSupported;
                    result.ErrorDescription = MsalErrorMessage.NonHttpsRedirectNotSupported;
                    callbackMethod(result);
                    this.DismissViewController(true, null);
                    return false;
                }


                return true;
            };

            _webView.LoadFinished += delegate
            {
                // If the title is too long, iOS automatically truncates it and adds ...
                this.Title = _webView.EvaluateJavascript(@"document.title") ?? "Sign in";
            };

            View.AddSubview(_webView);

            this.NavigationItem.LeftBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Cancel,
                this.CancelAuthentication);

            NSUrlRequest startRequest = new NSUrlRequest(new NSUrl(this._url));
            _webView.LoadRequest(startRequest);

            // if this is false, page will be 'zoomed in' to normal size
            //webView.ScalesPageToFit = true;
        }
开发者ID:AzureAD,项目名称:microsoft-authentication-library-for-dotnet,代码行数:83,代码来源:AuthenticationAgentUIViewController.cs

示例10: LoadingFinished

 public override void LoadingFinished(UIWebView webView)
 {
     try {
         var t = webView.EvaluateJavascript ("document.title");
         if (t.Length > 0) {
             _c.Title = t;
         }
     } catch (Exception error) {
         Log.Error (error);
     }
 }
开发者ID:jorik041,项目名称:odata,代码行数:11,代码来源:BrowserController.cs


注:本文中的UIWebView.EvaluateJavascript方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。