Created
July 26, 2012 06:18
-
-
Save ryugoo/3180537 to your computer and use it in GitHub Desktop.
TiWebView Link Remove
This file contains 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
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