-
-
Save yagitoshiro/2963853 to your computer and use it in GitHub Desktop.
WebView "Event to fire more than once" fix (removeEventListener)
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
// 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