Titanium Appcelerator - show back button in webview - webview

I use a webview and I show an external page; I would like that the back button appears only if there is a web history. I saw that exist a canGoBack() function, but I don't know how use this function.
NB my user see the webview (back button must be hidden) if the user click on the link and the web page is changed, the back button should be appear... if the user go back to the webview home , the back button disappear.
This code is triggered only when i load the webview for the first time, if navigate the webview the function is ignored:
if(webview.canGoBack()){
//webview.goBack();
Titanium.API.log('1');
}
else{
//win.close();
Titanium.API.log('0');
}
I hope I was clear. Thanks

Put this in the load event:
webview.addEventListener('load', function() {
if(webview.canGoBack()){
//webview.goBack();
Titanium.API.log('1');
}
else{
//win.close();
Titanium.API.log('0');
}
});
The load event is called every time the page changes.

Related

Is there a way to catch and cancel the back button event in a NativeScript app on the iOS platform?

I'm working on a NativeScript-Angular app for both Android and iOS but have hit a problem with standard back button navigation. I have resolved the issue for Android, but cannot find a solution for iOS.
The event is causing a problem when going back to a particular page where routing data is expected, resulting in the exception:
"Error: Currently in page back navigation - component should be reattached instead of activated".
My Android solution catches the back button event and cancels it, then calls the router to do the navigation.
ngOnInit() {
if (app.android) {
app.android.on(app.AndroidApplication.activityBackPressedEvent,
(args: any) => this.backEvent(args));
}
}
backEvent(args) {
args.cancel = true;
this.backToRegister(false);
}
backToRegister(accepted: boolean){
this.router.navigate(['/register',
this.registerParametersEntered.password,
this.registerParametersEntered.confirmPassword,
this.registerParametersEntered.code,
this.registerParametersEntered.email,
accepted]);
}
I want to do something similar with iOS, such as: -
if (app.ios) {
this.page.on('navigatingFrom', (data) => {
// TODO cancel the back button event
this.backToRegister(false);
})
}
I can't find a way of doing this for iOS - my research is leading me to the conclusion it is not possible to cancel the iOS back button - for example, see here.
Any ideas or alternative suggestions greatly appreciated!
You can't override the back button for iOS. See this SO question. You basically need to create a custom button, you can mimic the appearance of the back button on iOS and add your own event handler. That's how you'd do it in a native iOS app, and how you do it in NativeScript since the native controls are used via NativeScript.
The actionbar in nativescript can have a custom layout inside or you can just use an action-item and position it on the left for iOS, while also hiding the button on Android if you desire.
Another solution would be, instead of catching the back button event just to throw it away/disable it - to just clear the history after you are switching a page where there no "back" to go to.
this.router.navigate(['level1'], {
clearHistory: true
}

Navigate inside Modal

In the Instagram app on iOS you'll notice that when you logout, a modal pops up for signing in. If you click on signup then the page transition occurs inside that modal.
How could I achieve the same flow with nativescript?
You will need to call topmost().navigate() to navigate to your landing page on clicking the login button, you will also need to make a call to closeCallback() to hide the modal page.
This snippet might help -
On clicking the logout:
page.showModal("logoutModal", context, function(data){
console.log("Displaying Logout Modal");
}, fullscreenBoolean);
On clicking Login or some other button on modal:
export function moveTo() {
var navigationEntry = {
moduleName: "landingPage"
}
frame.topmost().navigate(navigationEntry);
closeCallback();
}
For more information: https://github.com/NativeScript/NativeScript/issues/3308
I just used the above code it worked fine for me.

Showmodaldialog help button in title bar

I have an HTA which opens a showmodaldialog and this JavaScript code in the dialog page:
function helpButton(){
document.body.style.curosor = "help";
my_div.onclick = function(){alert("Help for the div is displayed here")}
}
I want a help button in the title bar of the showmodaldialog, like on the picture below:
(don't mind about the fact that the picture's in French, it's my computer's language)
When I push on that help button, I want it to execute the helpButton() function.
There was showModalDialog('path', 'arg', 'help:yes'); and you could attach an onhelp handler within the opened dialog's window. However, this dialog property is obsoleted - since IE9, if I'd recall correctly - and can't be returned by downgrading the app using X-UA when running a HTA with a newer IE.
You still can set onhelp, and call it by hitting F1:
window.onhelp = function () {
alert('Help is asked.');
};

How to addd an 'close' button to a pdf loaded from within an app by uiwebview

We can use UIWEBVIEW to create a loading mechanism for viewing a pdf file when called in our app and we have successfully put in a 'close' or 'done' button that allows us to exit the pdf and return to the app. Our app is a website compiled using Xcode 5.1.
PROBLEM: Our 'close' / 'done' button appears on every page of our website app rather than only when the pdf is loaded. What we want is for the button to only appear when the pdf is loaded and when pressed, we can return to the app and the button disappears.
Any help very very much appreciated.
You can hide close and done button in other view like this
[closeBtn setHidden:YES];
[doneBtn setHidden:YES];
Make sure your other class able to access these buttons
if YOu Use PHONEGAP, you must use AppInBrowser
you can code like this
a href="javascript:void(0)" onclick="open_pdf('your.pdf');"
function open_pdf(url)
{ var ref = window.open(url, '_blank', 'location=no'); }
Follow :
Here's a link! And a reference-style link to [a panda][1].

Unable to use back button property in Popup screen in blackberry

In my application , am using popup screen, that implements FieldChangeListener.I used close() method for back button. but its not working.
Can some give sample code without using KeyListener,TrackwheelListener ?
if u want to close the popup screen on back button try this:
UiApplication.getUiApplication().
popScreen(UiApplication.getUiApplication().getActiveScreen());

Resources