Skip to content

Instantly share code, notes, and snippets.

@ryugoo
Created July 26, 2012 06:18
Show Gist options
  • Save ryugoo/3180537 to your computer and use it in GitHub Desktop.
Save ryugoo/3180537 to your computer and use it in GitHub Desktop.
TiWebView Link Remove
var App = App || {};
(function () {
var tabGroup = Ti.UI.createTabGroup();
tabGroup.addTab(Ti.UI.createTab({
title: "",
icon: "",
window: Ti.UI.createWindow({
title: "WebView",
backgroundColor: "#FFFFFF",
tabBarHidden: true
})
}));
var win = tabGroup.tabs[0].window;
var web = Ti.UI.createWebView({
url: "http://www.google.com/"
});
var appended = false;
web.addEventListener("beforeload", function (e) {
if (appended === false) {
web.evalJS("window.addEventListener('load',function(e){document.querySelector('html').innerHTML+='<titanium id=contentLoaded />';},false)");
appended = true;
}
});
web.addEventListener("load", function (e) {
var timer = setInterval(function () {
// aタグ中のhrefを全て空にしてしまう
web.evalJS("var allAnchor = document.getElementsByTagName('a'); for (var i = 0, l = allAnchor.length; i < l; i++) { allAnchor[i].href = ''; }");
var contentLoaded = web.evalJS("document.querySelector('titanium#contentLoaded').id");
if (contentLoaded === "contentLoaded" && appended === true) {
alert("DOMContentLoaded");
appended = false;
clearInterval(timer);
}
}, 250);
});
win.add(web);
tabGroup.open();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment