Created
May 27, 2011 19:03
-
-
Save hal-gh/995921 to your computer and use it in GitHub Desktop.
local and remote webview demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Titanium.UI.setBackgroundColor('#000'); | |
var win1 = Titanium.UI.createWindow({ | |
backgroundColor:'white', | |
exitOnClose:true, | |
layout:'vertical', | |
title:'win1: Main Window' | |
}); | |
Ti.App.addEventListener('fromWebview',function(e){ | |
Ti.API.info('from webview: '+e.msg); | |
}); | |
var buttonOpenLocal = Ti.UI.createButton({ | |
top:30, | |
title: "Open Local HTML Page" | |
}); | |
win1.add(buttonOpenLocal); | |
var buttonOpenRemote = Ti.UI.createButton({ | |
top:30, | |
title: "Open Remote HTML Page" | |
}); | |
win1.add(buttonOpenRemote); | |
buttonOpenLocal.addEventListener('click', function(){ | |
var win2 = Titanium.UI.createWindow({ | |
backgroundColor:'green', | |
fullscreen:false, | |
title:'win2: Local HTML Page' | |
}); | |
var webViewLocal = Ti.UI.createWebView({ | |
backgroundColor:'red', | |
url:'webview-local.html' | |
}); | |
win2.add(webViewLocal); | |
win2.open(); | |
}); | |
buttonOpenRemote.addEventListener('click', function(){ | |
// by design, this is not expected to work | |
var win2 = Titanium.UI.createWindow({ | |
backgroundColor:'green', | |
fullscreen:false, | |
title:'win2: Remote HTML Page' | |
}); | |
var webViewRemote = Ti.UI.createWebView({ | |
backgroundColor:'yellow', | |
url:'http://www.yourdomain.com/webview-remote.html' | |
}); | |
win2.add(webViewRemote); | |
win2.open(); | |
}); | |
win1.open(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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" xml:lang="en-GB"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
<title>webView Test Page</title> | |
<script type="text/javascript"> | |
//<![CDATA[ | |
function fire(m){ | |
Ti.App.fireEvent('fromWebview',{msg:m}); | |
} | |
//]]> | |
</script> | |
</head> | |
<body> | |
<a href="#" onClick="fire('hello from the local webview');">Click this link to execute the fire() function in the embedded script of this local page</a> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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" xml:lang="en-GB"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
<title>webView Test Page</title> | |
<script type="text/javascript"> | |
//<![CDATA[ | |
function fire(m){ | |
Ti.App.fireEvent('fromWebview',{msg:m}); | |
} | |
//]]> | |
</script> | |
</head> | |
<body> | |
<a href="#" onClick="fire('hello from the remote webview');">Click this link to execute the fire() function in the embedded script of this remote page</a> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment