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;
}
Related
Is there a way to use FB.XFBML.parse without rendering the a Facebook plugin again which cause it to "flicker" (disappear et reappear).
Will be using the Facebook Like button or Facebook Recommandations Bar.
Live example: http://www.gablabelle.com/eve-d
Slide to view the flickering in the lower right corner.
$.address.state(ajax_object.path).crawlable(true).value(whereiam);
$(".fb-recommendations-bar").data("href",whereiamurl);
//$(".fb-like").data("href",whereiamurl);
fburl = $(".fb-recommendations-bar").data("href");
//fburl = $(".fb-like").data("href");
console.log(fburl);
FB.XFBML.parse();
Many thanks for your help.
You can limit the scope of the re-parse by passing in the parent DOM element to FB.XFBML.parse.
Add an opacticy layer over the top of the facebook plugin div when a "page change" is needed. Animate it to fully opaque. Call the FB.XFBML.parse() and give it a few moments to re-render. Animate the layer to non-opaque, then remove the opacity layer from over the top of the facebook plugin div (or leave it there for the next time you need to do a "page change" without actually reloading the page.
This technique will give you a gracefully disappearing/reappearing plugin, rather than a jarringly harsh "flicker".
Cache the Facebook likes of the previous slide + current slide + next slide on a slide change event. So that when you go to the next or previous one and its Facebook like should already be ready/loaded, the user should not see a flickering. Unless he/she goes to fast with the slides.
I've had this recently.
I got around it by wrapping the XFMBL in a variable... don't know why but without it it seemed to flicker... a total hack of a way to stop the flickering but worked for me!!
if(call == 0){
FB.XFBML.parse();
call = 1;
}
DMCS provided what seems to be the only half-proper answer, but it's butt ugly. You don't know how long it'll take on each persons web browser to render the stuff. The callback which supposedly says it's rendered doesn't work either. Also the flicker isn't seen in firefox but only in google chrome.
Ok, weird issue:
1) Go here on an iPhone (Safari browser): http://powellcreative.com/our-team/
2) Click any of the team images to get to the team member page
3) Click the back button on the browser
4) The image is disappeared on the Team page now
I know this question is kind of old, but I was looking for a solution to a similar problem and after searching, I found a solution. Hopefully this helps other people with the same problem. The problem is when you give iOS a javascript event like onmouseover or onmouseout it doesn't like it, mainly because when your finger is "mousing over" an element in iOS, you are actually clicking on it, so this is the solution I came up with that seems to reload images after hitting the back button in iOS.
Here it is:
Make sure all images are in their own separate div with a distinctive name.
Example:
<div name="div1"><img src="yourimage" onmouseover="javascript:this.src='yourimage2';" onmouseout="javascript:this.src='yourimage';"></div>
In the javascript head part of your page you want to insert this:
window.onpageshow =
function(event){
if (event.persisted){
//for every div and image you want changed back you can add a loop here to change all at once or just one div by name//
document.getElementById('div1').innerHTML = '<img src="yourimage" onmouseover="this.src="yourimage2";" onmouseout="this.src="yourimage";">';
}
}
This will check for page back since Mobile Safari uses bfcache and reload your image into the div. Hopefully this helps OP or someone else.
Pretend you have a button on an iOS GUI. Pressing this button should now trigger a button on a webpage (which triggers an action). While doing this, the webpage should not be visible. How can I do that?
My guess is, that I read and parse the webpage, and if I've found the button action, I would trigger it somehow. Since I'm not a web programmer, I wonder how to proceed or read on for such a task.
I need this task, because there is no JSON or XML webservice on the page that would make life easier.
Many thanks for any input
Okay, let's say you've already loaded your webpage in an off-screen (or hidden) UIWebView, and the submit button on that webpage looked a bit like the following in code:
<form id="my_submit_button" etc... >
Just call the following:
NSString* javascript = #"document.forms['my_submit_button'].submit();";
[myUIWebView stringByEvaluatingJavaScriptFromString: javascript];
Hope this helps!
I have a properly functioning Eclipse RCP program which opens the org.eclipse.ui.intro extension to a home-page-id of root.xhtml. Inside of the root.xhtml home page, there are links to other XHTML pages to offer help.
I am trying to create buttons throuhout my GUI which, when you click them, they would take you to the correct XHTML documentation page. All I can figure out so far is how to get the buttons to take me to the root.xhtml page, but I cannot figure out how to tell the intro page to navigate to a different page. Here is the code I am using now to open the intro page:
help_button.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent event)
{
ActionFactory.INTRO.create(DataStore.getInstance().getCurrentWorkbenchPage().getWorkbenchWindow()).run();
}
})
For example, I am trying to do something like this where the hyperlink string in quotes is exactly the same as the hyperlink in the root.xhtml file:
ActionFactory.INTRO.create(DataStore.getInstance().getCurrentWorkbenchPage().getWorkbenchWindow()).run().navigateTo("http://org.eclipse.ui.intro/showPage?id=setuplogging");
I was able to figure this out, it was rather time consuming and painful to do so - hopefully it helps someone out. At least the answer is a few lines of code.
You have to show the intro site getIntroSite() first before changing the URL otherwise you will get a null pointer exception in IntroURL. If you get the null pointer exception when calling createIntroURL(), it may have to do with an intro site not being already open in your GUI, not necessarily that your link is bad. Also, if the intro is already open, don't try to reopen it because it will change the page to the home page rather than your page identified with page_id. So, for this class, I made the help button a toggle button meaning if the intro window is open, then the button is pressed. In some cases I close the intro site if it is already open when the button is pressed (example below), in other cases I just don't update the intro site so it won't go to the home page (example not shown, but just omit the first part of the if block).
If you try the ActionFactory run() code in my question, that will display the intro site in the entire Window. I wanted the intro site to be a sub-window within the perspective, so I used the method below by setting showIntro(null, true) - true meaning don't take up the entire window (they call the Boolean standby).
The page_id corresponds to the page id setup in your documentation XML file when setting up your extension point org.eclipse.ui.intro.config content variable.
final IIntroPart
intro = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().
getWorkbenchWindow().getWorkbench().getIntroManager().
getIntro();
if (PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().
getWorkbenchWindow().getWorkbench().getIntroManager().
isIntroStandby(intro))
{
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().
getWorkbenchWindow().getWorkbench().getIntroManager().
closeIntro(intro);
help_button.setSelection(false);
}
else
{
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().
getWorkbenchWindow().getWorkbench().getIntroManager().
showIntro(null, true).getIntroSite();
IIntroURL
introURL = IntroURLFactory.createIntroURL(
"http://org.eclipse.ui.intro/showPage?id=" + page_id);
introURL.execute();
help_button.setSelection(true);
}
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