URL change but not request webview ios - ios

everyone.
I am building an hybric app that using web and Xcode. First time, I use a webview to open web app in which it contains a menu (on main screen). I use shouldStartLoadWithRequest to get request URL before it request. Then when user touch a button on that menu, I see that URL changes but shouldStartLoadWithRequest method not get called, I need to get URL in that method before it requests to know where it will navigate. Can anyone explain for me? I have no knowledge about web. Thank you very much.

As I understand it, the function shouldStartLoadWithRequest gets called only for urls which is going to load content or, load new webview frame.
There are few kind of urls which might be assigned to javascript that doesn't actually load a page, may not work. Do you need to intercept it before the link navigation occurs.
Also it would help provide better answers if you gave details of the action (<a href="..."> or javascript) that the manu link will perform.

I can not figure out what is the problem but the following is my trick:
I detect that the URL changes but it does not request data. I use UITapGestureRecognize to detect when user taps to webview and perform an action after delay 0.01s to get URL. At this time, URL change to new URL of new page. After get URL I implement corresponding to that URL.

Related

UIWebView with NavigationBar

Imagine there is a list of posts and if you click a postItem, then a detailed post view shows up. For example,
/index
[post1, post2, post3 ...]
post1 is clicked
/posts/1
Hello! I am a post!
Also, the website that will be included inside the UIWebView is a single page web app, which makes things a little tricky. Since the webapp renders parts instead of redirecting, navigation doesn't necessarily make another web request. For regular websites that make a new url request for every navigation, I can use either webViewDidStartLoad or shouldStartLoadWithRequest, having one ViewController per webpage. A naive solution for my case would be forcing a fresh redirect for every navigation, using window.location = url.
However, that loses the performance boost coming from rendering specific parts. A better way to do it is attaching a navigationItem such as title and back button dynamically when the user moves away from the index page. The problem is, how do I detect whether the user moved to /posts/1 from /index if I am not doing a full redirect?
Thank you so much in advance!
For your last idea to bind the title and back button you could use the following, but you will need to modify the website code.
You can communicate with your native controller from the webview using a custom protocol / scheme of url.
The idea is to make a call like window.location = 'myapp://thisismyaction/thisisanarg' when you need to update.
Once the call is made you intercept it with -(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType.
In this method you parse your request to detect if it start with myapp:// and you parse the line to get your action and your args. The syntax is up to you like regular queryString or else as in my example. You do your update and the title based on what you parse and you return NO to prevent loading a non-existant URL.
To make sur that this call is only happening from webview and not a browser, you could inject some javascript object when you webview finish loading with stringByEvaluatingJavaScriptFromString method from the webview, and check if the object is defined before making the call from the javascript.

Using history.back() in UIWebView but loaded pre page contains very old data

IOS 8.0+
My app use UIWebview to visit a forum site.
The forum front page contains two tag: default one is 'Recommend', another one is 'Newest'. Using ajax to load post data When user switch to 'Newest' tag, at the same time the page runs the follow codes to save state:
window.history.pushState(null, title, url);
After that if user is interesting with some post, he/she would click link and jump to a new page to view detail of the post. In this page, I use follow code to let user have a way to go back to 'Newest':
history.back(-1);
Now interesting thing happened, go back to 'Newest' tag but post data is old.
After some tests, I found the data is always be the first time loaded after installed the app. This bug will not happen in Safari or Android app.
I believe it should have some relationship with webView cache.But why UIWebview does't use new cache? And how to
solve this problem?
Oh no...nobody meet this problem?
My current solution is:
use js code to auto refresh the page when go back.

Reload a UIWebView every request?

I have a UIWebView and I'm trying to get links to open in Safari. The usual code works, just not with m.youtube.com. So I'm trying a different approach - is there a way of, every time the webView is loading, the page is completely reloaded but with the new URL instead? This is the only solution I can think of.
Here is the question I'm referencing:
Open in Safari from UIWebView (using youtube.com)
Thanks.

How can i do like the Pinterest unique modal process?

I have a question that
Point> I don't want to know generally function of modal, but like Pinterest
Question core > 1. Can i change the URL when i use ajax without "reloading"
Work flow >
1) On Pinterest, i click on a image
2) A modal window opens up, but the URL of the page also changes without "reloading"
even though it use ajax
I've known that when i using a modal function, it dosen't change the URL on the page,
but not on Pinterest
URL change e.x) rootURL -> otherURL
3) I click the background of the modal, the URL of the page also changes without "reloading"
and modal windows closed
URL change e.x) otherURL -> rootURL
So, If you have some solution or information, please let me know that.
Also I have red related question answers, but it's not enough. and don't want to get information obout HTML5 API cause i'm not going to provide HTML5 service
How can I duplicate Pinterest website's modal effect?
Pinterest like ajax loading
Changing the Url without a HTML call
Manage in the same url the Full HTML document and a JSON object (or a partial HTML response)
you can do like this http://mazzimo-in-london-eng.blogspot.com/2013/01/the-pinterest-url-sorcery-how-pinterest.html

ajax request changing url

I have a pager on a table using ajax and I would like each such request also to change the browser's url, so when I hit refresh button I won't skip back to first page. I was fighting the Url parameter of AjaxOptions, but it keeps winning over me. Please help.
Trim
You can safely change the URL past the hash mark without redirecting the page. However, the user can (in most browsers) navigate through these changes with the Back and Forwards buttons. This technique is usually called "history."
Because the technique is difficult to get working in all browsers, you'll want to use a framework. Take a look at http://www.mikage.to/jquery/jquery_history.html.
I can also recommend ExtJS's history stuff too. Take a look at this example:
http://www.extjs.com/deploy/dev/examples/history/history.html#main-tabs:tab2
Again, notice that not only does the URL change when the user does stuff, but changing the URL (via Back and Forward) also affects the page. This is good, awesome even, but means it must be done very carefully.
There is not really a quick and easy way to do this, here is an article on the topic. The problem is that not only does the Ajax have to generate the URLs, it also has to take those URLs into account when loading the page to get the appropriate content.

Resources