Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vid-n3t/5219725 to your computer and use it in GitHub Desktop.
Save vid-n3t/5219725 to your computer and use it in GitHub Desktop.
<script type="text/javascript" src="http://www.java.com/js/deployJava.js"></script>
<script type="text/javascript">
//Find browser (for non Safari)
if( ! jQuery.browser.safari ){
/* *********************************
* Modify deployJava.getBrowser()
********************************* */
/**
* Usage: browserDetect(); //execute the script
*/
browserDetectScript=""; //set defaults
//capture remote script contents, minus the surrounding function() and brackets {}
browserDetectScript = deployJava.getBrowser.toString().replace('function (){','').replace(/\}$/,'');
//console.log(browserDetectScript); //view the original script contents
//check the function contents for any key piece
if(browserDetectScript.indexOf("return this.browserName")){
//edit the function
//return a different var
browserDetectScript = browserDetectScript.replace('return this.browserName','return this.browserName2');
//remove the log comments
browserDetectScript = browserDetectScript.replace('g("[getBrowser()] navigator.userAgent.toLowerCase() -> "+n);','');
browserDetectScript = browserDetectScript.replace('g("[getBrowser()] Detected browser name:"+this.browserName+", "+this.browserName2)','');
}
//create the new function
var browserDetect = new Function(browserDetectScript);
//console.log(browserDetect.toString()); //view the modified script contents
/* *************************************
* END Modify deployJava.getBrowser()
************************************* */
} else {
function browserDetect(){
return "Safari";
}
}//end if not safari
//Browser compatibility
currentBrowser = browserDetect();
if( !currentBrowser.length > 0 ) {
currentBrowser = yourBrowser();
}
console.log(yourOS() + ' + ' + currentBrowser);
</script>
//Console output; Note the return statement at the end of each code block here:
if(this.browserName==null){var n=navigator.userAgent.toLowerCase();g("[getBrowser()] navigator.userAgent.toLowerCase() ->
"+n);if((n.indexOf("msie")!=-1)&&(n.indexOf("opera")==-1)){this.browserName="MSIE";this.browserName2="MSIE"}else{if(n.indexOf("iphone")!=-1){this.browserName="Netscape
Family";this.browserName2="iPhone"}else{if((n.indexOf("firefox")!=-1)&&(n.indexOf("opera")==-1)){this.browserName="Netscape
Family";this.browserName2="Firefox"}else{if(n.indexOf("chrome")!=-1){this.browserName="Netscape
Family";this.browserName2="Chrome"}else{if(n.indexOf("safari")!=-1){this.browserName="Netscape
Family";this.browserName2="Safari"}else{if((n.indexOf("mozilla")!=-1)&&(n.indexOf("opera")==-1)){this.browserName="Netscape
Family";this.browserName2="Other"}else{if(n.indexOf("opera")!=-1){this.browserName="Netscape
Family";this.browserName2="Opera"}else{this.browserName="?";this.browserName2="unknown"}}}}}}}g("[getBrowser()] Detected browser
name:"+this.browserName+", "+this.browserName2)}return this.browserName
function anonymous() {
if(this.browserName==null){var
n=navigator.userAgent.toLowerCase();if((n.indexOf("msie")!=-1)&&(n.indexOf("opera")==-1)){this.browserName="MSIE";this.browserName2="MSIE"
}else{if(n.indexOf("iphone")!=-1){this.browserName="Netscape
Family";this.browserName2="iPhone"}else{if((n.indexOf("firefox")!=-1)&&(n.indexOf("opera")==-1)){this.browserName="Netscape
Family";this.browserName2="Firefox"}else{if(n.indexOf("chrome")!=-1){this.browserName="Netscape
Family";this.browserName2="Chrome"}else{if(n.indexOf("safari")!=-1){this.browserName="Netscape
Family";this.browserName2="Safari"}else{if((n.indexOf("mozilla")!=-1)&&(n.indexOf("opera")==-1)){this.browserName="Netscape
Family";this.browserName2="Other"}else{if(n.indexOf("opera")!=-1){this.browserName="Netscape
Family";this.browserName2="Opera"}else{this.browserName="?";this.browserName2="unknown"}}}}}}}}return this.browserName2
}
Macintosh + Firefox
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment