How to navigate back to a Page and avoid reloading webview? - webview

I have a Windows Phone Store app (XAML) with a Page (MainPage.xaml) that has a webview that loads content and URLs. At certain point i have to navigate to a different windows phone page (Page2.xaml), once the data there is submitted i navigate back to MainPage.xaml, but the webview control always reloads the content and user has to reenter the data again.
Is there any way to make a snapshot of the webview and load it when Navigating back to MainPage.xaml?
I have tried the NavigationHelper, but in the onNavigatingFrom event from MainPage when i try to save the Frame.Content, its the Page2 the one being passed in the NavigationEventArgs.
Any ideas?

One way to do it is to never leave the page. To do this, create two grids. One for the webview and one for the other view. When the page loads, show the first grid and hide the second grid. When you want to show the second view hide the first grid and show the second.
I have used this method in several apps on the phone and windows store and you can simulate popups this way as well.

Related

Why doesn't rails turbo-stream-from update the dom outside the tab?

Why doesn't rails turbo-stream-from update the dom when we're not in the application tab in the browser?
When we go back to the tab in the browser where the application is, all items are inserted at once at this point.
I don't know the logic exactly
but I think there are 2 possibilities:
it uses Browser Window focus event, so the update will be done when the user has opened the tab
it's a limitation from the browser, to prevent unnecessary CPU usage, it doesn't want to update the content if user is focusing on another tab

How does iOS 13 Safari link preview work?

In iOS 13 Safari, when you long press on a link, you see a preview of the linked page, along with some menu items. If you tap the preview, you navigate to that page.
Now, I see how to intervene in the long-press-and-preview process. This used to be peek-and-pop, but in iOS 13 that's deprecated and we're supposed to use func webView(_:contextMenuConfigurationForElement:) and so forth. Fine, but how would I imitate what Safari does?
The problem is that as my preview provider I have to supply a view controller. So I'm going to need a different view controller with a web view showing the linked page. Okay, I can do that. But then when the user taps the preview to dismiss it, I want to respond by loading the same linked page into my real web view.
But that's the problem. That loading takes time. In Safari, by contrast, when you tap the preview, boom, there's the same page already loaded. How do they do that? How would I do the same thing? How can I load the page into a different view controller, cache it, and communicate that cached page back to my real web view?

How to navigate to different page while coming back from activity in WL.NativePage.show()?

My scenario is this: I am using WL.NativePage.show(nativePageClassName, backFromNativePage, params) to navigate to an activity. Once returning back to the WebView, I need to navigate directly to other page(Div) in html, rather from the page I originally navigated from to the activity, which is developed using jQuery-Mobile.
See the below example code.
WL.NativePage.show("com.example.SignatureActivity", function(data) {
if(data.goToPage == "example2"){
$.mobile.changePage('#example2-page',{transition: 'none'});
}else{
$.mobile.changePage('#example1-page',{transition: 'none'});
}
});
Here I am using WL.NativePage.show() In example1-page, I have two buttons in activity, one is save and one is back, while saving I need to navigate to example2 and while back, its example1.
I am able to navigate to example2, but example1-page is executing and displaying first and then displaying example2-page.
Please give me suggestions on how to navigate directly to example2-page without displaying example1-page.
You can't navigate directly from the activity to a different place in the DOM which is in the WebView from which you navigated to the activity.
What you could do, is open displaying the activity, also hide the current content in the WebView. I assume it is a DIV essentially - so you could do something with display:none or any other standard method.
That way when the user returns back to the WebView from the activity and the code to change page is executed, you could then play again with the visibility of the DIV to display it when needed.
This way what you don't want to be seen will not be shown.

How to avoid a blink when UIWebView loads HTML

I have a native iOS app that contains a tab bar. The view controller for each tab contains a UIWebView. When the user switches between tabs, I load the HTML in the corresponding web view. The HTML is fully cached on a device. Here is how I feed the HTML to UIWebView:
[self.webView loadHTMLString:htmlString baseURL:baseUrl];
baseUrl is a file URL pointing to a directory where all assets are located.
This works great in online and offline modes, however it takes time for the UIWebView to parse and render the HTML. As a result, the user sees a brief blink of a white background when switching between tabs. I'd like to remove it, because the user is able to tell that the UI is not native (native UI renders instantly).
I was thinking about taking a screenshot of the UIWebView once it's done rendering the HTML and caching it in memory. The next time the user navigates to that web view, the app displays the screenshot while the UIWebView is rendering the HTML in the background. Finally, the app swaps the screen shot with the actual UIWebView and takes a new screenshot. This is similar to how Google Chrome app works.
Does anyone know a better solution to this problem?
Depends on how you present that web view. I'm not really sure from your description how you do it, but since you're talking about a blink of white background, I'm going to assume there is a situation where you have a web view with a loaded html and then you switch it to another html. The solution for that case would be:
create a second web view,
load the new html to this new web view,
when that web view finishes loading html (you can find out if you use UIWebViewDelegate) you can then quickly switch it with your old web view (meaning you finally add the new web view to the view hierarchy at THIS point, not when you created it).
This way you'll have an instant switch between old and new html, however user will be left waiting and it is your decision what to do with it. You could use UIActivityIndicatorView for example.
When webViewDidFinishLoad: gets called you can do any number of things, make the webview visible, remove something that you had on top of the webview etc...

Prevent ios pinned app refresh

How do I stop a pinned web page from refreshing each time the user clicks its' icon.
I have created a jqm web app with the idea that users pin it to their home page. However each time I press the corresponding icon it reloads the page. I'd like it to remain in the last viewed state until an explicit refresh is called. Is this possible?
Thanks
Not alot to go on here...
Have you tried to bind .preventDefault() to the pinned items.
$(youritems).on('click', function(e){
e.preventDefault;
});

Resources