Suppose my app will load a local web page which is stored in my app bundle. I want to push the view or present a view when the user click a link or an image inside that web page. How to do this? Let's make this be general question: how to communicate with my app from a local web page?
Thank you.
Use "webview.request.URL.absoluteString" to get the request-string of the clicked link in the delegate-method "webViewDidFinishLoad:" or "webViewDidStartLoad:".
then you can scan this url for some special substring.
For example you could make a link like ".../index.php?iPhone_action=abcdef".
In the delegate-methods you can check if the link has the substring "?iPhone_action=" and if it does, then put the part of the link, whick follows "?iPhone_action=" in a NSString.
(in our example it would be "abcdef").
Depending on the value of this NSString you could fire a action in your app.
There is an undocumented method to catch the event when you click on a link in UIWebView. You can do whatever you want to do in that method.Search on google/stackoverflow for it. Or see my answer in this stackoverflow post.
Show alert view when click on a link
Related
I need to be able to figure out what is the previous page in a UIWebView hierarchy so that I can disable the back button on certain instances. So, to clarify:
User is on page A - clicks on link
User is now on page B - clicks on link
User is now on page C - clicks on the **back** button
User is now on page B
I need to be able to know that "previous" page from page B is page A. The method I'm using right now unfortunately only figures out the previous page the user was in in general. So in the situation above, it thinks the previous navigated page is page C.
Any help would be appreciated! :)
Each time the user clicks on a link and a new page loads, your web view delegate gets a message. So "write down" that information each time! Now you know what "back" means.
Also, you can talk JavaScript to the UIWebView. JavaScript gives you a history object. A lot of the key functionality in UIWebView is through JavaScript! Apple hasn't bothered to duplicate it in Objective-C properties, because, well, why bother?
years later....
In researching this same scenario, I came up with a nice solution.
Inside webViewDidFinishLoad, check for the property "canGoBack" and hide or unhide your back button accordingly. Thought this was too cool not to share. :)
if (self.webView.canGoBack)
{
self.backButton.hidden = NO;
}
else
{
self.backButton.hidden = YES;
}
I am just building an app for my first time. I've created it so that I open it and it opens web view and I have a button called "Save" (so it's just a web view inside the app with a little button below it). I would like to be able to save a website when I visit it. It doesn't need to label the save or anything, I just want it to save and I can click another button called "sites" and it will display my list of saved websites.
You will have to decide on some kind of storage method. A simple one would be create an NSMutableArray of the sites. Depending on the needs of the application, you could change this to something different. Then, saving the site is as simple as inserting an object that represents the page (maybe an NSURL or an NSString with the URL). The question Get current URL of UIWebView discusses several ways of getting a URL from a webview. You can then decide on a way to display the list of saved sites. Once a site is selected, you just have to pass it back to the webview.
Using Woodwing, we have a page that has custom html in it, using the custom web widget.
That widget has an anchor tag, that when tapped, opens a page in safari.
However, if we create the same page using the HTML widget, and a link overlay, that triggers a ModalView to display.
I'm assuming this has something to do with WoodWing's (un)documented protocols for the anchor tags, that are captured by the WoodWing shell application and used to trigger the "ModalView" display. Since everything in Woodwing generates an XML that is parsed when the app is loaded, and I've done numerous applications, this seems reasonable. However, there is very little technical documentation.
My question is: does anyone know any documentation on those protocols, or a way I can use custom-html to trigger the ModalView? I've tried replacing "http" with "ww" but no dice. It's possible it's javascript but I'm suspecting protocols...
The UIWebViewDelegate defines the webView:shouldStartLoadWithRequest:navigationType: method that your view controller can implement. In this implementation, your code shoudl decide if it wants to handle the request (user click) or let the UIWebView handle it normally.
For displaying a modal as a result of a click, this method would display the modal and return NO.
The default HTML widget implementation doesn't support this out of the box. There are two ways that you can do to achieve this;
Implement what they call a 'custom object'. They documented this feature, if you have access to their documentation this should be relatively easy to figure out. It allows you to write native objects and inject them into both the .ofip format and the application.
Implement a modal dialog within the widget (in HTML). This is less convenient but possible to do (if you have a fullscreen widget).
Create the specific URL for open as you mention in your comment(ww://string.string).
Then in UIWebView Delegate method (webView: shouldStartLoadWithRequest: navigationType:) get the redirect URL. If redirect URL is equal to you mention before then perform your action.
Let me know if this answer help you.
Thanks,
Is it possible to load a URL without a visible view?
Basically I'm trying to submit some information to my server by a php page. It works from my webViewController, which has a working view, but not from my appDelegate, which doesn't have a visible view.
I recommend you use ASIHTTPRequest to submit the information to your php page.
In my app I have a WebView Containing a Twitter account for and every tweet there is a link take you to a specific website
my question : can I replace the links of those webpages by read more ?
You can override the link itself so that when the user clicks, instead of it jumping to that website, it calls your method.
Create an instance of UIWebViewDelegate,and implement the method:
"webView:shouldStartLoadWithRequest:navigationType:
Sent before a web view begins loading
content."
...and return "false" when the link clicked is one of those external links.
Then, also, do whatever custom action you wanted to do - e.g. popup a new UIView that contains the "read more" content you wanted to display