当旧浏览器不接受jquery时的替代方案

时间:2021-08-19 17:28:01

I have just been altered to the fact that a user of my website is using a very old browser which does not run jquery (in this case Safari 1.x) and as a result can not access the login panel which uses jquery's slideToggle function.

我刚刚改变了这样一个事实:我的网站的用户正在使用一个非常旧的浏览器,它不运行jquery(在这种情况下是Safari 1.x),因此无法访问使用jquery的slideToggle函数的登录面板。

Can anyone think of a fix which detects whether a browser is able to use jquery - and if not make that link go to a different page rather than showing the login panel?

任何人都可以想到一个修复程序,它可以检测浏览器是否能够使用jquery - 如果不能使该链接转到另一个页面而不是显示登录面板?

8 个解决方案

#1


2  

In the plain HTML source code for the the href= of the login link, set that to a plain HTML login page.

在登录链接的href =的纯HTML源代码中,将其设置为纯HTML登录页面。

Using jQuery, attach the click handler to the link, if this part fails, thats ok, the browser will just follow the href in the link to the plain login page, allowing your old-browser-user to login still.

使用jQuery,将单击处理程序附加到链接,如果此部分失败,没关系,浏览器将只关注到普通登录页面链接中的href,允许旧浏览器用户登录。

$(document).ready(function(){
  $('#login_link_id').click(function(){
    // Your code here
  });
});

#2


5  

You could a little conditional check like

你可以进行一些有条件的检查

if(!'jQuery' in window) {
    // jQuery is not available
}

or, if Safari 1.x doesn't know about the IN operator (I'm not sure) use

或者,如果Safari 1.x不知道IN运算符(我不确定)使用

if(!window.jQuery) {
}

#3


4  

I think there are alternative answers to this, but for me, I would have to weigh up the time it will take you to support his obsolete browser (I'm sure there may be other things inside the site), versus the payback to you...

我认为还有其他的答案,但对我而言,我将不得不权衡你支持他过时的浏览器的时间(我确信网站内可能有其他东西),而不是回报给你...

#4


1  

If you use javascript/jQuery you should ALWAYS ensure your site works perfectly without it. In this case if you have a login popup box; you probably assign a click event assigned after the DOM has loaded.

如果您使用javascript / jQuery,您应该始终确保您的网站在没有它的情况下完美运行。在这种情况下,如果您有一个登录弹出框;你可能会分配一个在加载DOM后分配的点击事件。

What you should do is ensure that if jQuery isn't present the link loads a "normal" login webpage as opposed to the popupbox. I use something similar to this:

你应该做的是确保如果jQuery不存在,链接加载“普通”登录网页而不是弹出框。我使用类似的东西:

<a href="/login.html" id="loginlink">Log in</a>
<script>
    if(!'jQuery' in window) {
        $(document).ready(function(){
            //assign on click event to loginlink
        });
    }
</script>

If jQuery doesn't exist then login.html will be opened normally.

如果jQuery不存在,那么login.html将正常打开。

#5


0  

Wow, seriously?! Safari 1.x?? Anyhow, try this...

哇,真的吗?! Safari 1.x ??无论如何,试试这个......

var isJQSupported = false;

$(function() { //shorthand for document.ready

  isJQSupported = true;

  //your usual code


});

if (!isJQSupported) {

  window.location = "http://www.apple.com/safari/download/";

}

#6


0  

To me it sounds like safari 1.X has problems with jQuery internally. Which means simple checks like whether $ exists in the global space or whether $(function) does anything are not going to help.

对我来说,这听起来像safari 1.X内部有jQuery问题。这意味着简单的检查,例如全局空间中是否存在$或者$(函数)是否有任何帮助。

The most likely root cause will be that javascript throws an error in loading of jQuery itself which will then stop the rest of your javascript code from execution.

最可能的根本原因是javascript会在加载jQuery本身时抛出错误,然后会停止执行其余的javascript代码。

There are four viable options here.

这里有四种可行的选择。

  • Either make the website work with noscript. Replace your login control with pure HTML and postbacks and ask the user to turn javascript off. This option is useful since you won't be fixing the issue for safari 1.x problems specifically.
  • 要么使网站与noscript一起使用。用纯HTML和回发替换您的登录控件,并要求用户关闭javascript。此选项很有用,因为您不会特别修复safari 1.x问题。
  • You can make javascript check for safari 1.X and other non-supported browsers and only load jQuery through script tag injection or ajax if your user is using a supported browser. If the user is using a browser not compatible with jQuery then you can instead use plain javascript.
  • 您可以对safari 1.X和其他不支持的浏览器进行javascript检查,并且只有在用户使用支持的浏览器时才通过脚本标记注入或ajax加载jQuery。如果用户使用的浏览器与jQuery不兼容,那么您可以使用普通的javascript。
  • Get a copy of safari 1.x and see why jQuery breaks. Then fix it and ask for it to pulled into the release of jQuery 1.5. This relies on the fix being something that does can be done without hacking and that the jQuery team agrees is worth adding in.
  • 获取safari 1.x的副本,看看为什么jQuery会中断。然后修复它并要求它进入jQuery 1.5的发布。这依赖于修复是可以在没有黑客攻击的情况下完成的,并且jQuery团队同意值得添加。
  • Ask the user to use a compliant browser.
  • 要求用户使用兼容的浏览器。

There might be some more options. I would personally lean towards asking the user to use a compliant browser because supporting Safari 1.x is ridiculous.

可能还有更多选择。我个人倾向于要求用户使用兼容的浏览器,因为支持Safari 1.x是荒谬的。

#7


0  

This seems like a case where progressive enhancement is needed.

这似乎是需要逐步增强的情况。

You have to do multiple checks

你必须做多次检查

  1. see if $ exists
  2. 看看$是否存在
  3. see if $.fn exists
  4. 看看$ .fn是否存在
  5. [not sure if needed] check if $.support is a function
  6. [不确定是否需要]检查$ .support是否为函数
  7. check for feature support as needed with $.support() http://api.jquery.com/jQuery.support/
  8. 根据需要使用$ .support()http://api.jquery.com/jQuery.support/检查功能支持

At the end of the check, when jQuery reports that features you need are present - the rest of the script can run.

在检查结束时,当jQuery报告您需要的功能时 - 脚本的其余部分可以运行。

If you're not sure which features mentioned in the support you use, then this might need a single test on Safari 1.x to see what are the values returned by $.support(), but that is what your nasty old-browser-user can do for you (if you prepare code and publish) and report the resulting text. Then you compare the list with other [old] browsers that are accessible and determine features that are required.

如果你不确定你使用的支持中提到了哪些功能,那么这可能需要在Safari 1.x上进行一次测试,以查看$ .support()返回的值是什么,但这就是你讨厌的旧浏览器 - 用户可以为您做(如果您准备代码并发布)并报告生成的文本。然后,将列表与可访问的其他[旧]浏览器进行比较,并确定所需的功能。

The easy way would be to require everything and cancel all scripts if suport for any feature is missing. This will also rule out IE6 and IE7 and opera below 9.something and firefox below 2.0 or including - I'm not sure.

如果缺少任何功能,那么简单的方法就是要求所有内容并取消所有脚本。这也将排除IE6和IE7以及低于9.something和firefox低于2.0或包含的歌剧 - 我不确定。

#8


0  

Use a server side language to detect if it's the old safari based on user-agent and load a different javascript file

使用服务器端语言来检测它是否是基于用户代理的旧Safari,并加载不同的javascript文件

#1


2  

In the plain HTML source code for the the href= of the login link, set that to a plain HTML login page.

在登录链接的href =的纯HTML源代码中,将其设置为纯HTML登录页面。

Using jQuery, attach the click handler to the link, if this part fails, thats ok, the browser will just follow the href in the link to the plain login page, allowing your old-browser-user to login still.

使用jQuery,将单击处理程序附加到链接,如果此部分失败,没关系,浏览器将只关注到普通登录页面链接中的href,允许旧浏览器用户登录。

$(document).ready(function(){
  $('#login_link_id').click(function(){
    // Your code here
  });
});

#2


5  

You could a little conditional check like

你可以进行一些有条件的检查

if(!'jQuery' in window) {
    // jQuery is not available
}

or, if Safari 1.x doesn't know about the IN operator (I'm not sure) use

或者,如果Safari 1.x不知道IN运算符(我不确定)使用

if(!window.jQuery) {
}

#3


4  

I think there are alternative answers to this, but for me, I would have to weigh up the time it will take you to support his obsolete browser (I'm sure there may be other things inside the site), versus the payback to you...

我认为还有其他的答案,但对我而言,我将不得不权衡你支持他过时的浏览器的时间(我确信网站内可能有其他东西),而不是回报给你...

#4


1  

If you use javascript/jQuery you should ALWAYS ensure your site works perfectly without it. In this case if you have a login popup box; you probably assign a click event assigned after the DOM has loaded.

如果您使用javascript / jQuery,您应该始终确保您的网站在没有它的情况下完美运行。在这种情况下,如果您有一个登录弹出框;你可能会分配一个在加载DOM后分配的点击事件。

What you should do is ensure that if jQuery isn't present the link loads a "normal" login webpage as opposed to the popupbox. I use something similar to this:

你应该做的是确保如果jQuery不存在,链接加载“普通”登录网页而不是弹出框。我使用类似的东西:

<a href="/login.html" id="loginlink">Log in</a>
<script>
    if(!'jQuery' in window) {
        $(document).ready(function(){
            //assign on click event to loginlink
        });
    }
</script>

If jQuery doesn't exist then login.html will be opened normally.

如果jQuery不存在,那么login.html将正常打开。

#5


0  

Wow, seriously?! Safari 1.x?? Anyhow, try this...

哇,真的吗?! Safari 1.x ??无论如何,试试这个......

var isJQSupported = false;

$(function() { //shorthand for document.ready

  isJQSupported = true;

  //your usual code


});

if (!isJQSupported) {

  window.location = "http://www.apple.com/safari/download/";

}

#6


0  

To me it sounds like safari 1.X has problems with jQuery internally. Which means simple checks like whether $ exists in the global space or whether $(function) does anything are not going to help.

对我来说,这听起来像safari 1.X内部有jQuery问题。这意味着简单的检查,例如全局空间中是否存在$或者$(函数)是否有任何帮助。

The most likely root cause will be that javascript throws an error in loading of jQuery itself which will then stop the rest of your javascript code from execution.

最可能的根本原因是javascript会在加载jQuery本身时抛出错误,然后会停止执行其余的javascript代码。

There are four viable options here.

这里有四种可行的选择。

  • Either make the website work with noscript. Replace your login control with pure HTML and postbacks and ask the user to turn javascript off. This option is useful since you won't be fixing the issue for safari 1.x problems specifically.
  • 要么使网站与noscript一起使用。用纯HTML和回发替换您的登录控件,并要求用户关闭javascript。此选项很有用,因为您不会特别修复safari 1.x问题。
  • You can make javascript check for safari 1.X and other non-supported browsers and only load jQuery through script tag injection or ajax if your user is using a supported browser. If the user is using a browser not compatible with jQuery then you can instead use plain javascript.
  • 您可以对safari 1.X和其他不支持的浏览器进行javascript检查,并且只有在用户使用支持的浏览器时才通过脚本标记注入或ajax加载jQuery。如果用户使用的浏览器与jQuery不兼容,那么您可以使用普通的javascript。
  • Get a copy of safari 1.x and see why jQuery breaks. Then fix it and ask for it to pulled into the release of jQuery 1.5. This relies on the fix being something that does can be done without hacking and that the jQuery team agrees is worth adding in.
  • 获取safari 1.x的副本,看看为什么jQuery会中断。然后修复它并要求它进入jQuery 1.5的发布。这依赖于修复是可以在没有黑客攻击的情况下完成的,并且jQuery团队同意值得添加。
  • Ask the user to use a compliant browser.
  • 要求用户使用兼容的浏览器。

There might be some more options. I would personally lean towards asking the user to use a compliant browser because supporting Safari 1.x is ridiculous.

可能还有更多选择。我个人倾向于要求用户使用兼容的浏览器,因为支持Safari 1.x是荒谬的。

#7


0  

This seems like a case where progressive enhancement is needed.

这似乎是需要逐步增强的情况。

You have to do multiple checks

你必须做多次检查

  1. see if $ exists
  2. 看看$是否存在
  3. see if $.fn exists
  4. 看看$ .fn是否存在
  5. [not sure if needed] check if $.support is a function
  6. [不确定是否需要]检查$ .support是否为函数
  7. check for feature support as needed with $.support() http://api.jquery.com/jQuery.support/
  8. 根据需要使用$ .support()http://api.jquery.com/jQuery.support/检查功能支持

At the end of the check, when jQuery reports that features you need are present - the rest of the script can run.

在检查结束时,当jQuery报告您需要的功能时 - 脚本的其余部分可以运行。

If you're not sure which features mentioned in the support you use, then this might need a single test on Safari 1.x to see what are the values returned by $.support(), but that is what your nasty old-browser-user can do for you (if you prepare code and publish) and report the resulting text. Then you compare the list with other [old] browsers that are accessible and determine features that are required.

如果你不确定你使用的支持中提到了哪些功能,那么这可能需要在Safari 1.x上进行一次测试,以查看$ .support()返回的值是什么,但这就是你讨厌的旧浏览器 - 用户可以为您做(如果您准备代码并发布)并报告生成的文本。然后,将列表与可访问的其他[旧]浏览器进行比较,并确定所需的功能。

The easy way would be to require everything and cancel all scripts if suport for any feature is missing. This will also rule out IE6 and IE7 and opera below 9.something and firefox below 2.0 or including - I'm not sure.

如果缺少任何功能,那么简单的方法就是要求所有内容并取消所有脚本。这也将排除IE6和IE7以及低于9.something和firefox低于2.0或包含的歌剧 - 我不确定。

#8


0  

Use a server side language to detect if it's the old safari based on user-agent and load a different javascript file

使用服务器端语言来检测它是否是基于用户代理的旧Safari,并加载不同的javascript文件