Skip to content

Instantly share code, notes, and snippets.

@ryugoo
Created June 20, 2012 23:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ryugoo/2963029 to your computer and use it in GitHub Desktop.
Save ryugoo/2963029 to your computer and use it in GitHub Desktop.
WebView "Event to fire more than once" fix (removeEventListener)
// Global Background Color
Ti.UI.setBackgroundColor("#000000");
// Namespace
var APP = {};
// Running
(function () {
// Window
var win = Ti.UI.createWindow({
title: "WebView",
backgroundColor: "#FFFFFF"
});
// WebView
var webView = Ti.UI.createWebView(),
attach = function (e) {
APP.beforeURL = e.url + "";
webView.removeEventListener("load", attach);
alert("Loading");
};
webView.setUrl("http://www.google.com/");
webView.addEventListener("load", attach);
webView.addEventListener("beforeload", function (e) {
var currentURL = e.url + "";
if(currentURL !== APP.beforeURL) {
webView.addEventListener("load", attach);
}
});
win.add(webView);
// TabGroup
var tabGroup = Ti.UI.createTabGroup();
tabGroup.addEventListener("focus", function (e) {
APP.currentTab = e.tab;
});
// Tab
var tab = Ti.UI.createTab({
title: "WebView",
icon: "KS_nav_views.png",
window: win
});
tabGroup.addTab(tab);
tabGroup.setActiveTab(tab);
// Open
tabGroup.open();
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment