当浏览器是IE时运行JQuery函数 [英] Run JQuery function when browser is IE

查看:100
本文介绍了当浏览器是IE时运行JQuery函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图根据用户是否运行IE来运行JQuery函数。原因是因为我拥有的功能在IE中不起作用,所以当用户使用IE时,我想另外运行另一个功能。我正在运行JQuery 1.9.1,所以我不能使用 $。browser 。我试图使用有条件的评论,但我不确定这是否应该走。我试图在这里实现它,但它不起作用: http://jsfiddle.net/AsQ4E/



这是HTML

 <! - [如果IE]> 
< input type =buttononclick =javascript:ie();值=点击我! />
<![endif] - >

<! - [if!IE]> - >
< input type =buttononclick =javascript:notIE();值=点击我! />
<! - <![endif] - >

这是JQuery

 函数ie(){
alert(您正在使用IE);


函数notIE(){
alert(您没有使用IE);
}

我怎样才能使它工作?这是最好的方式吗?






编辑:我正在尝试使用SVG Crowbar。当用户点击一个按钮时,Crowbar会从页面中提取一个SVG并弹出一个下载。以下是它的链接: http://nytimes.github.io/svg-crowbar/。问题在于它在IE中不起作用,所以我只打算在用户使用IE时使用它: http://bl.ocks.org/biovisualize/1209499 (这在IE中起作用)。我对编程和Javascript没有足够的了解,无法用IE来调试问题。

解决方案

使用导航器的JavaScript

  navigator.userAgent.indexOf('MSIE')

现在如果你真的想要IE和版本,你应该从msdn中检查这个脚本



更有效地检测Windows Internet Explorer


I am trying to run a JQuery function based on whether or not the user is running IE. The reason is because the function that I have does not work in IE, so I have another one I would like to run instead when the user is using IE. I am running JQuery 1.9.1, so I cannot use $.browser. I'm trying to use conditional comments, but I'm not sure if that is the way to go. I've tried to implement it here, but it doesn't work: http://jsfiddle.net/AsQ4E/

This is the HTML

<!--[if IE]>
    <input type="button" onclick="javascript:ie();" value="Click Me!" />
<![endif]-->

<!--[if !IE]> -->
    <input type="button" onclick="javascript:notIE();" value="Click Me!" />
<!-- <![endif]-->

This is the JQuery

function ie() {
    alert("You are using IE");
}

function notIE() {
    alert("You are not using IE");
}

How can I get this to work? Is this the best way to go about it?


EDIT: I am trying to use SVG Crowbar. When the user clicks a button, Crowbar extracts an SVG from the page and pops up a download for it. Here is the link to it: http://nytimes.github.io/svg-crowbar/. The problem is is that it doesn't work in IE, so I was going to use this only when the user is using IE: http://bl.ocks.org/biovisualize/1209499 (This works in IE). I don't know enough about programming and Javascript to debug the problem with IE.

解决方案

With javascript using navigator

 navigator.userAgent.indexOf('MSIE')

Now if you really want the IE and the version you should check this script from the msdn

Detecting Windows Internet Explorer More Effectively

这篇关于当浏览器是IE时运行JQuery函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆