I am working on an app where I have custom buttons that I want to direct the user to a website. I have not found examples or navigation options for this and looking for the documentation on this.
My code is:
var button = Ti.UI.createButton({ backgroundImage:'button1.png', title: 'website 1', //font:{fontsize:40, fontFamily:'Helvetica Newe'}, top: 3, width: 190, height:45 }); button.addEventListener('click', function(e) { Go to website http://www.google.com (example site)Where do I learn about a button that takes you to a website? Im not sure if I need to create a new window for this or the most efficient way Appcelerator handles this.
Thank you for any advice, suggestion, feedback, etc..
Regards, John
7 Answers
Accepted Answer
Hi John
This is the line of code you need
Ti.Platform.openURL('http://www.google.com');And this is the documentation for openURL that walks you through it.
Thank you AGAIN! I appreciate you. John
This as well worked out great, but the navbar disappeared when the webView came up. Is there a way to keep that there so the user can go back to the menu after visiting this site? Malcolm if you are still here will the "choices" option work?
Thank you, John
Another way would be to create a webView in a window in your application. Then set the url of the webView to you desired URL.
It provides for a better user experience and the user will not need to figure out how to get back inside of your application
I guess I dont quite have it down yet because I was trying to configure it to open in a new window and feel like I did exactly how you suggested based on your second suggestion but Navbar still disappears. Can you tell where Im missing something or have something that should not be there?
var webview = Ti.UI.createWebView({ height: 440, top: 0, width: 320 }); var button5 = Ti.UI.createButton({ backgroundImage:'button1.png', title: 'LSP Website', //font:{fontsize:40, fontFamily:'Helvetica Newe'}, top: 10, width: 220, height:70 }); button5.addEventListener('click', function(e) { var win10 = Titanium.UI.createWindow({ width: 320, height: 480, top: 0, left: 0, backgroundImage: 'images/background.png' }); webview.setUrl('http://www.google.com'); win10.add(webview); win10.open();This launched the page but the Navbar still disappeared. Striving for independence from the forums.
Any ideas?
Thank you, John
OK so I re-wrote the code identical to yours and Im getting a "cant find variable at line 35, which is the win1.add(button); line. I have to use that because it is actually button 5 and just because I have so many windows I used 20 so as to not confuse it with anything else. Here it is:
Ti.UI.setBackgroundColor('#000'); var button, win1 = Ti.UI.createWindow({ title : 'Tab 1', backgroundColor : '#fff' }); var button5 = Ti.UI.createButton({ title : ' website 1', top : 3, width : 190, height : 45 }); button5.addEventListener('click', function(e) { var wvwin20, webview = Ti.UI.createWebView({ width: '100%', height: '100%', url : 'http://www.google.com/' }); wvWin20 = Titanium.UI.createWindow({ title: 'My School', backgroundColor : '#fff' }); wvWin20.add(webview); wvWin20.open({ modal : true }); }); win20.add(button5); win20.open();The one thing I find odd is your code shows "open" in blue and mine does not. Is that a clue to anything?
Thanks a bunch, John
Hey I just saw your comments and not offended at all. Yes, I have gone through the docs and videos and I know it seems like I have not. I have learned a ton from it but am coming straight out of Xcode and Objective C and I think Im just trying to learn too much too fast. I was explaining to Malcolm earlier that the CEO has put so much pressure on me to get this done that Im pulling all nighters the last few days and the brain is probably mush. Its not usually like this I promise. You wont see this behavior from me regularly because I hate having to ask questions but she put a deadline of Monday on me to solve a ton of issues so I have been in this chair for the majority of the last 4 days.
I appreciate your guidance and look forward to putting this problem app behind me and then sitting down and starting at the beginning of the documentation and going through it properly rather than just surfing around for fixes to another developers problems.
Im not looking for pity either....just added this because you asked. I will either have this app and its issues solved tonight or be done with it tomorrow. Thanks again!
Respectfully, John
Your Answer
Think you can help? Login to answer this question!