Reputation: 3660
I have a large HTML5 app and am using Titanium to add native support to it. The easiest hello world for me is:
var webview = Titanium.UI.createWebView({url:'http://myApp.com'});
var window = Titanium.UI.createWindow();
window.add(webview);
window.open();
But if I try using the Titanium API from within my existing code it has no reference. Is there an config file option that will make that Titanium API available to my web app?
I just found this in the docs:
Scripts downloaded from remote web servers cannot access the Titanium namespace,
however, you can use the web view evalJS method to execute a JavaScript
expression inside the web view, and retrieve the value of an expression.
Aside from polling the context of the webview is there any way to have the context access the Titanium API?
Upvotes: 1
Views: 1268
Reputation: 581
load all your html file in different .JS file using web-view and try with doing this code
Applicationwindow.js file if you want android Option menu keep this code else modify
according to your events.
function ApplicationWindow() {
//declare module dependencies
var All = require('ui/common/All');
Tree = require('ui/common/Tree');
EBOM = require('ui/common/E-BOM');
MBOM = require('ui/common/M-BOM');
SBOM = require('ui/common/S-BOM');
//create object instance
var self = Ti.UI.createWindow({
title:'Products',
exitOnClose:true,
navBarHidden:true,
backgroundColor:'#ffffff',
/////////////////////////////////////////////////////////////////////////////
activity: {
onCreateOptionsMenu: function(e) {
var menu = e.menu;
var menuItem = menu.add({ title: "C-BOM", icon: 'Arrow-Hover.jpg' });
//menuItem.setIcon("Arrow-Hover.jpg");
menuItem.addEventListener("click", function(e) {
var all = new All();
self.add(all);
});
var menuItem = menu.add({ title: "ALL-BOM" });
menuItem.setIcon("images/refresh_icon.png");
menuItem.addEventListener("click", function(e) {
var tree = new Tree();
self.add(tree);
});
var menuItem = menu.add({ title: "E-BOM" });
menuItem.setIcon("images/refresh_icon.png");
menuItem.addEventListener("click", function(e) {
var ebom = new EBOM();
self.add(ebom);
});
var menuItem = menu.add({ title: "M-BOM" });
menuItem.setIcon("images/refresh_icon.png");
menuItem.addEventListener("click", function(e) {
var mbom = new MBOM();
self.add(mbom);
});
var menuItem = menu.add({ title: "S-BOM" });
menuItem.setIcon("images/refresh_icon.png");
menuItem.addEventListener("click", function(e) {
var sbom = new SBOM();
self.add(sbom);
});
var menuItem = menu.add({ title: "Logout" });
menuItem.setIcon("Arrow-Hover.jpg");
menuItem.addEventListener("click", function(e) {
alert("Logout");
});
}
}
/////////////////////////////////////////////////////////////////////////////
});
var webview = Titanium.UI.createWebView({
url:'/ui/common/Login.html'
});
self.add(webview);
return self;
};
module.exports = ApplicationWindow;
Upvotes: 0
Reputation: 1831
I agree with Aaron, PhoneGap does sound better for what you're trying to do. However, if you still want to do this in Titanium.....
The short answer is you'd have to run Ti.App.fireEvent() from the webview, which will allow you to run a function call from a Titanium javascript file. From the Titanium javascript file, you would add an event listener with Ti.App.addEventListener.
For a more detailed example, we'd need more context.
Upvotes: 1
Reputation: 33345
save yourself some time and use phonegap, what you are doing is not a best practice for Appcelerator
Upvotes: 1