Please help me to find the way how to navigate back on webviewclient using back button on android.
I am using Xamarin hybrid app using Razor views,
I am using loadDataWithBaseURL method to find each method and move on that page, like following:
if (method == "SignIn")///sign-in.html
{
var template = new SignIn();
var page = template.GenerateString();
webView.LoadDataWithBaseURL("file:///android_asset/", page, "text/html", "UTF-8", null);
}
The above code I am using in ShouldOverrideUrlLoading(WebView webView, string Url)
the URL is passed as "hybrid:SignIn?"
Now back navigation is not working either on using OnBackPressed() method, or using OnKeyDown()
I also tried, WebBackForwardList, I can see in debug mode te current items in it , but no any url to go back on.
The url is always "about:blank"
and page is showing blank on GoBack() method.
Related
When the push notification is pushed from server side, the default Urban Airship message center is displayed on the app using
UAirship.defaultMessageCenter().display()
and tapping on the messages displays the message details. The content of message details page is an HTML payload which is part of the push notification triggered by server side. I need to call a swift function when a button on the WebView is tapped. Since we don't have access to the WKWebView presented in the view controller which is provided by UA, I am not able to call any swift function from javascript. Please suggest.
Consider using Urban Airship's actions framework which can be used to trigger native code from a message center webview.
First, define your custom UAAction.
let swiftAction = UAAction(block: { (args: UAActionArguments, handler: UAActionCompletionHandler) -> Void in
print("Action is performing with: \(args)")
handler(UAActionResult.empty())
})
Then register the action after takeOff.
UAirship.shared().actionRegistry.registerAction(swiftAction, name:"swift_action")
You can then modify your HTML content to run the action from your message. Use the runAction method on the UAirship object which is inserted in the message center webview.
UAirship.runAction("swift_action", "arguments", function() {return true})
Additional resources:
Urban Airship Javascript Interface
Custom Actions
I'm trying to open a specific page in my app (not the home page) and use the following piece of code
private void toastNotification(string Content,string uri)
{
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);
XmlNodeList textElements = toastXml.GetElementsByTagName("text");
textElements[0].AppendChild(toastXml.CreateTextNode("FootBallTards"));
textElements[1].AppendChild(toastXml.CreateTextNode(Content));
var toastNavigationUriString = "/Views/Browser.xaml?uri="+uri;
var toastElement = ((XmlElement)toastXml.SelectSingleNode("/toast"));
toastElement.SetAttribute("launch", toastNavigationUriString);
ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(toastXml));
}
The toast notification is being fired correctly but on tapping them, the home located in Views/Home.xaml (absolute address) page of my app is being opened, but I want to redirect to page located in Views/Browser.xaml (absolute address), and also pass the parameter uri to that page.
Apart from this how can I get the value of parameter on that page. I've looked up help from stackoverflow question , stackoverflow question and msdn page but couldn't get it to work.
I am working on windows phone 8.1 runtime universal app and using webview to go to page. I want to be able to download the HTML on the page into a string so I can use t in my app. I have used these links for help but to no avail:
http://codesnack.com/blog/2012/01/05/metro-webview-source-workarounds/
Retrieve Inner Text from WebView HTML in Windows/Windows Phone 8.1
https://social.msdn.microsoft.com/Forums/windowsapps/en-US/331fa2db-3efa-40e2-af08-ddebe9424869/how-to-get-html-source-information-of-webview-in-windows-phone-81?forum=winappswithcsharp
so I added this line in my NavigationCompleted event handler
string pageContent = webBrowser1.InvokeScriptAsync("eval", new string[] { "document.documentElement.outerHTML;" }).ToString();
But when I step through the code all I get is System.__ComObject as the value for pageContent .
Any ideas what is going on here?
Thanks!
InvokeScriptAsync returns a IAsyncOperation not a string. If you call ToString() on it you'll just get the type of the object (System.__ComObject).
You'll almost always want to "await" Async functions like this. That will process the returned operation, wait for it to finish, and then return its type.
If you change your code to the following then pageContent will get the HTML from your evaled function:
string pageContent = await webBrowser1.InvokeScriptAsync("eval", new string[] { "document.documentElement.outerHTML;" });
For this code:
var Root = new RootElement("ConnectionView")
{
new Section("Sales")
{
new HtmlElement("Discover more about foo",
"http://foo.com")
}
}
var dvc = new DialogViewController(Root, true);
this.NavigationController.PushViewController(dvc, true);
this.AddChildViewController(dvc);
this.View.AddSubview(dvc.View);
The dialog is created as expected, with headers and elements.
However, although the HtmlElement opens the URL as anticipated, it navigates the app to a full-screen display of the web site without any navigation methods for returning to the dialog proper. Other elements that open views retain the navigation controller as expected and do not open full screen.
Note: I am using the flag on the DialogViewController to enable Nav.
Without doing much work, the simplest thing to do is to make sure that your DialogViewController is hosted in a UINAvigationController, which will provide a simple way of going back.
Alternatives include subclassing the HtmlElement and adding your own UI to control that.
I'm trying to create an MVVM Caliburn-based WinRT 8.1 app (I know that CM won't be perfectly compatible with 8.1 until version 2.0 is out, but the error does not seem to be related, as it is raised also when the handler is placed in the view code behind). One of its views contains a WebView control, whose content is set via NavigateToString (HTML contents come from app's installed assets). The HTML loaded into this control includes several hyperlinks, most of them representing cross-references to other asset-based HTML content. So when users click the link I want to override the standard navigation action, get my viewmodel notified, and let it load another HTML content from the app assets.
Here is what I did, following the post Open links in external browser in WebView (WinRT):
in the XAML code, I added to the WebView control an attribute for attaching the ScriptNotify event to my VM: cal:Message.Attach="[Event ScriptNotify] = [Action GetFromLink($eventArgs)]" (see https://caliburnmicro.codeplex.com/wikipage?title=All%20About%20Actions).
in my VM, the method signature is public void GetFromLink(NotifyEventArgs e).
whenever my VM loads some HTML into the WebView, it first injects a script in the HTML head which replaces the click handler of each anchor representing a cross-reference (all these anchors are marked by a class="xref" attribute). This script is hold in a constant in my VM:
private const string SCRIPT = "for (var i = 0; i < document.links.length; i++) {" +
"var className = document.links[i].getAttribute(\"class\");" +
"if (className && className === \"xfer\") {" +
"document.links[i].onclick = function() {" +
"window.external.notify('url:' + this.href);" +
"return false;" +
"}}}";
Now, when I launch the app, load an item containing one of these xref's and click on it, I get an unhandled exception telling me that "navCancelInit is undefined". I suppose this error is surfacing from JS code, but I cannot see where and how this function should be defined.
According to http://msdn.microsoft.com/library/windows/apps/br227713, I do not need any additional step for ScriptNotify when HTML has been loaded via NavigateToString. Could anyone suggest a solution?
I got an answer from a MS guy about this, so credit is not mine for this answer: it is a timing issue. I must ensure that the page has fully loaded before running the script which changes the DOM; pretty simple, if you think. Just moving the script at the end of the page, or wrapping it in an onload handler, should make the trick. Hope this can save some hair-pulling to others!
If you listen to this event: http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.webview.domcontentloaded.aspx WebView.DOMContentLoaded event, All of the script should be loaded in the WebView and you should be able to access and execute, if you are trying to do this before the scripts won't be loaded.