How do I get my button to redirect to a web page within the app? - codenameone

So far, I have it so that when a user presses a button, a browser opens and redirects the user to my desired url. However, I want this to happen within the app instead of a web tab. How can I do this?

Use the BrowserComponent, just add it to the center of a border layout form and set the URL for that component. Check out the list of main components in Codename One within the developer guide.

Define a xml layout containing a widget called webview. Then in your activity you implement a listener to your button which invokes that xml with the desired page to load inside your webview. Google to find some code and return here with your code problems, if you find some. If this will be the case, open new questions provinding detailed info about your matters then we can help more. Best.
EDIT: Excuse me, just now, re-reading your question I think I really understand it, and the solution is very simple, just a line of code (to instruct your app to open a webpage inside your webview, and not the regular browser, outside your app). Try this:
wv = (WebView) findViewById(R.id.myWebView);
wv.setWebViewClient(new WebViewClient()); // needed to open url inside our webview, otherwise it will open at the default browser
wv.loadUrl(url);

Related

How to attach tracking code to anchored link for an email newsletter while retaining scroll to view?

I'm trying to figure out how to attach a tracking code to a link and still keep the anchor functional. This will be used in an email newsletter.
ex:
www.example.com/welcome#Intro so that link would scroll down to the intro section right?
now if I were to do the same thing but like this www.example.com/welcome#Intro?TrackingCode the scroll no longer works.
I tried to google it but I couldn't find anything, any suggestions?
thanks for your time!
Don't think you can track scrolls. The images load top to bottom. We can't use anything like lazy load as JavaScripts don't work in emails unless it's viewed in the browser. If you want to use on browser then you can use jQuery to do that.

CocoonJS webview: Going back a page

I'm just trying out a simple app in the CocoonJS launcher which contains some links that open some external page.
This works fine, but the problem is that I can't identify a way to go back a page (i.e. history back). The launcher app just displays the page in fullscreen, no user controls visible at all. This is troublesome, because when my users tap on an ad, I want them to be able to go back to the game.
Am I missing something or is this simply not supported?
I do not know of any way to display a navigation bar or something similar.
Nevertheless, you can open your external urls via Cocoon.App.openURL(url); which will enable the user to open it via a normal browser where you can navigate back.
Regards.
I agree with the solution proposed by Scdev. Also, interstitials or fullscreen ads usually have a dismiss button themselves. I might be misunderstanding something.
Regards,
Iker.

How to open application from a webbrowser windows phone

I am developing a windows phone application.
In a page I placed a button and on this button click I open the webbrowser and redirects to our website pages for some processes. There are many webpages. In the last webpage we added a button "Close". In the close button click I want to close the webbrowser and open the application back with the last state before opening the webbrowser. How can I do this ?
Thanks.
I will refer to the button in the app as "app button" and the button in the web page as "close button".
Add a WebBrowser control called webBrowser1 to the Windows Phone app. Make it cover the entire screen, and set it's Visibility property to Collapsed.
On the app button's click event, use
webBrowser1.Visibility = System.Windows.Visibility.Visible;
webBrowser1.Navigate(new Uri("http://yourwebsite.com/page");
to show the web browser and navigate it to the first page on your website.
Make the close button on the last page of your site navigate to a new page on your site, called "close.html" or whatever you want. In javascript, this would look like
<Button onclick="window.location.href='http://yourwebsite.com/close.html';">
Back in the app: On webBrowser1's Navigating event use,
if (e.Uri.ToString().Contains("close.html"))
{
webBrowser1.Visibility = System.Windows.Visibility.Collapsed;
}
When the you click the button on the last page of your site, it navigates to "close.html". When this happens, the Web Browser's Navigating event fires. Since this event fires every time you change pages, you need to check to see if the new url contains "close.html", the page your close button is navigating to. If it does, the Web Browser will be hidden and you will see your app again.
.
(In VB, the code would be )
webBrowser1.Visibility = System.Windows.Visibility.Visible
webBrowser1.Navigate(New Uri("http://yourwebsite.com/page")
And
If e.Uri.ToString.Contains("close.html")
webBrowser1.Visibility = System.Windows.Visibility.Collapsed
End If
Edit: I was thinking in generic terms when i wrote the answer and did not remember that you are asking specifically about the webbrowser (hence, using a webbrowsertask launcher). Thank you #Claus for point out the OAuth situation. So, i am amending my answer to explain that it is possible and also mention an issue with using the launcher as there is no way guarantee to return back to a given point in your launcher app (as it is with choosers due to the availability of callbacks).
It is not possible to achieve this in general terms. That is, there is an application A which opens another application B and from application B you would like to close-it-and-open-A. There are many reasons why i think it is not possible:
- How does one get the address/reference to the application A. No API for that at the moment.
- There is no content-handler/plugin where a 3rd party can register an app with the web-browser.
- Most importantly, security, security, security. This would open doors for attacks from the web.
However, for your requirement of application B being a web-browser, it is possible to use a task launcher WebBrowserTask. As #claus suggests, you could have Window.close() javascript in your last page to close the browser and hence reveal the app underneath it (hopefully, A). The problem here is that if, the user opens an app (let's call it C) after the browser has launched (and before the browser is closed), and the user does not close C, then when the browser gets closed, the user will be returned to C and not to the launcher App! This is not what you want based on your requirement.
So, if you would like to achieve the kind of effect you are describing in your question, it is best that you embed the Web-browser in your application (as a full-screen app) and from that vantage point you can interact between the web-browser (control) and the (host) app via Javascript.
Hopefully, this helps.

Windows Phone show ConnectionSettingsTask and back

I am working on a windows phone app right now.
In the app, I am handling an exception in page 1, that when there is no wifi connection, it will pop a XNA messagebox, user can choose to open the WIFI settings page. I have the following code:
ConnectionSettingsTask connectionSettingsTask = new ConnectionSettingsTask();
connectionSettingsTask.ConnectionSettingsType = ConnectionSettingsType.WiFi;
connectionSettingsTask.Show();
But the problem with this is, when user hit back key in the wifi settings page, they will be navigate back to page 1, which has a loading problem and can not display the proper content. In this case, I would like user to directly go to another page, call it page 2.
Is that possible? Thank you
++++++++++++++Update
Is there are way to customize the back key functionality when showing the XNA messagebox?
I don't know about XNA coding much, but I do know that if you return from wifi connection page to your app, the OnNavigatedTo function is invoked. Try setting out your flow of code according to the application flow. If there is some code you have executed at the constructor, shift it to OnNavigatedTo and vice-verse, which may solve your problem. Also if you want to shift to another page, do it in the same function (OnNavigatedTo) itself. Hope it helps.
Maybe you can change the navigation behavior: http://blogs.msdn.com/b/ptorr/archive/2010/08/28/redirecting-an-initial-navigation.aspx
However it is recommended to merge the two pages together (hide loading bar and show main page) as you will have less problems...
why not handle this code in the IsNetworkAvailable check? that way you'l avoid the exception altogether

A Link Inside an iFrame That Pops Up "Photo Theater"

I have a tab with an iframe external web page that loads... I would love a hyperlink inside that web page to link one of my photo albums in "theater" mode so you don't leave the page. However, any link I program inside that web page just brings in that photo album inside (not popped up and not in theater mode no matter if I have the &theater in the url).
Can I get some help on how to do this? Thanks!
this is a limitation of iframes in general. Less of a limitation and more of a security issue. As you said.. the iframe loads and external page - a page that could essentially come from anywhere. To protect the integrity of the site displaying this external page, the iframe can not access the page that contains it.
You might want to try opening a new window using javascript :
window.open ("{path_to_image}","title","menubar=1,resizable=1,width=350,height=250");
as you can see there are several options that you can set to customize the popup window.
Here is another link with some info about iframes

Resources