积极答复者
如何去除自动判断语句?

问题
-
初学程序,看了一些实例还是有些不清楚
例如
var isChrome = navigator.userAgent.indexOf("AppleWebKit") != -1;
var isFirefox = navigator.userAgent.indexOf("Firefox") != -1;
var url = window.location.href.toLowerCase();
function beginExecute() {……………………
……………………
}
if (url.indexOf("zh-tw.facebook.com") >= 0 || url.indexOf("www.facebook.com") >= 0 || url.indexOf("/search") >= 0 || url.indexOf("/url") >= 0) { if (!isChrome && !isFirefox) { alert("很抱歉,未能识别您的浏览器,请使用Firefox或Chrome浏览器!"); } else if (isFirefox && "undefined"===typeof(GM_notification)) { alert("很抱歉,本脚本需要最新的Scriptish扩展、不支持GreaseMonkey,请禁用您的GreaseMonkey扩展并安装Scriptish!"); window.open("https://addons.mozilla.org/zh-CN/firefox/addon/scriptish/"); } else { window.onload = beginExecute(); } }
如何将这段代码的“判断浏览器”的语句删除变为简单的语句,让它直接运行,不去判断浏览器???求指导
Wer keinen starken Willen hat, kann nie eine hohe Intelligenz erreichen.
- 已编辑 Gnade 2013年3月20日 11:10
答案
-
if (url.indexOf("zh-tw.facebook.com") >= 0 || url.indexOf("www.facebook.com") >= 0 || url.indexOf("/search") >= 0 || url.indexOf("/url") >= 0) { window.onload = beginExecute(); }
Mike Feng
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- 已标记为答案 Gnade 2013年3月24日 9:34
-
var isChrome = navigator.userAgent.indexOf("AppleWebKit") != -1; var isFirefox = navigator.userAgent.indexOf("Firefox") != -1;
开头的这两句到底要不要??
Wer keinen starken Willen hat, kann nie eine hohe Intelligenz erreichen.
Mike Feng
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- 已标记为答案 Gnade 2013年3月24日 9:34
全部回复
-
同意楼上,那几个if就是判断浏览器的,你把他们都删掉 就剩那一句了
Mike Feng
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help. -
Hi Solok,
从你给出的代码来看 就是这样的。
Mike Feng
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help. -
if (url.indexOf("zh-tw.facebook.com") >= 0 || url.indexOf("www.facebook.com") >= 0 || url.indexOf("/search") >= 0 || url.indexOf("/url") >= 0) { window.onload = beginExecute(); }
Mike Feng
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- 已标记为答案 Gnade 2013年3月24日 9:34
-
var isChrome = navigator.userAgent.indexOf("AppleWebKit") != -1; var isFirefox = navigator.userAgent.indexOf("Firefox") != -1;
开头的这两句到底要不要??
Wer keinen starken Willen hat, kann nie eine hohe Intelligenz erreichen.
Mike Feng
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- 已标记为答案 Gnade 2013年3月24日 9:34