Hi I am unable to open remote html file in titanium using webview. i am using Titanium sdk 2.0.1 GA2 android.runtime: rhino My code is
app.js
var window = Titanium.UI.createWindow({ fullscreen: true, backgroundColor: "#000", navBarHidden: true }); var webview = Titanium.UI.createWebView({url:http://172.27.47.54/SampleProj/file.html'}); window.add(webview );
Ti.App.addEventListener('openURL', function(e){ Ti.Platform.openURL(e.url); });
on remote server file is
file.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>test</title> <script type="text/javascript"> function fireEvent() { Titanium.App.fireEvent('app:openURL', { url:'http://172.27.47.54/SampleProj/file2.html'}); } </script> </head> <body> <a onclick="fireEvent()">Draft Enrollment Form</a> </body> </html>
I really appreciate you if you will give me the answer Thanks in advance
4 Answers
Well, there seem to be a quote missing in the code you just pasted.
Titanium.UI.createWebView({ url: 'http://172.27.47.54/SampleProj/file.html' });
and not:
Titanium.UI.createWebView({url:http://172.27.47.54/SampleProj/file.html'});
Hello Ravi,
Try like this,
var window = Titanium.UI.createWindow({ fullscreen : true, backgroundColor : "#000", navBarHidden : true }); var tr = '<html><body><iframe id="myFrame" class="youtube-player" type="text/html" width="320" height="440" src="http://www.youtube.com/embed/rFT6X7rkB3w" frameborder="0"></iframe></body></html>'; var webview = Ti.UI.createWebView({ html : tr, backgroundColor : 'black' }); window.add(webview); window.open();
First, PLEASE use the markdown syntax so that people can read your code. I don't understand why so many people have this problem. The system makes you preview before you post -- don't you see how horrible your code looks when you don't use the markdown????
From the docs for WebView:
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.
The bottom line is this: you can't fire an event back to your app if the HTML document is a remote document.
Even if your content were local, you have a mismatch in the event you're firing and the event you're listening for:
Titanium.App.fireEvent('app:openURL', {...}); Ti.App.addEventListener('openURL', ...);The name must be exactly the same in both places. I would recommend using
app:openURL in both places.
@Permalink: Thanks for the answer but what i want html file should be call from remote server not locally. i don't want to write html in any local file or in my application folder.
Your Answer
Think you can help? Login to answer this question!