Created
September 19, 2012 00:09
-
-
Save ezy/3746858 to your computer and use it in GitHub Desktop.
Conditional JS
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
<script type="text/javascript"> | |
function removejscssfile(filename, filetype){ | |
var targetelement=(filetype=="js")? "script" : (filetype=="css")? "link" : "none" //determine element type to create nodelist from | |
var targetattr=(filetype=="js")? "src" : (filetype=="css")? "href" : "none" //determine corresponding attribute to test for | |
var allsuspects=document.getElementsByTagName(targetelement) | |
for (var i=allsuspects.length; i>=0; i--){ //search backwards within nodelist for matching elements to remove | |
if (allsuspects[i] && allsuspects[i].getAttribute(targetattr)!=null && allsuspects[i].getAttribute(targetattr).indexOf(filename)!=-1) | |
allsuspects[i].parentNode.removeChild(allsuspects[i]) //remove element by calling parentNode.removeChild() | |
} | |
} | |
if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) | |
{ | |
removejscssfile("somescript.js", "js") //remove all occurences of "somescript.js" on page for ipad & iphone | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment