基于浏览器加载不同的HTML文件

基于浏览器加载不同的HTML文件

本文介绍了基于浏览器加载不同的HTML文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定这是否可能,但使用谷歌搜索导致我没有明确的答案。有没有办法根据浏览器类型加载一组不同的HTML?



这是我唯一的情况下唯一的选择。我已经尝试了其他一切,我将能够使其工作的唯一方法是将完全不同的HTML文件放入Internet Explorer 10及更低版本,并使用完全不同的脚本和资源。我有一个脚本需要保持在加载顺序的顶部才能正常运行(谷歌聚合物js文件),我还需要检测浏览器是否为ie10或更低版本,并且能够告诉浏览器不加载文件如果是这样的话,因为它会导致很多错误,所以在页面下面会加载任何其他东西。



所以,是的 - 任何方式来切换基于浏览器吗?最好能用ie10和以下的东西?任何信息或链接将不胜感激。谢谢!



编辑我不能使用条件注释,因为我需要它与ie10一起工作,并且它们移除了对条件的支持。 :($ /

编辑我现在可以检测到IE10和以下罚款感谢Siropo,但我不知道如何让文件加载之前其余的页面......就像我需要检查浏览器是否为IE10及其以下版本,然后将文件加载到其他所有内容中。是否有办法让所有事情等待,直到我查看了浏览器类型?如果您只需要检测IE的不同版本而不是其他浏览器,则可以使用IE特定的HTML条件:

p>



如果您使用框架来构建支持您的网站某种模板系统,您可以依靠请求中的User-Agent为不同的浏览器呈现不同的HTML模板。


I am not sure if this is even possible, but googling has lead me to no clear answer. Is there a way to load a different set of html based on browser type?

This is seriously the only option for my unique case. I've tried everything else and the only way I'm going to be able to make it work is by putting in an entirely different html file with entirely different scripts and resources for Internet Explorer 10 and below. I have a script that needs to remain at the top of the load order in order to function correctly (google polymer js file) and I need to also detect if the browser is ie10 or below and be able to tell the browser to not load that file if so, as it's causing so many errors that nothing else will load below it on the page.

So, yes -- any way to switch which html loads based on browser? Preferably something that would work with ie10 and below? Any info or links would be appreciated. Thank you!

edit I cannot use a conditional comment because I need it to work with ie10 and they removed support for conditionals. :(

edit I can now detect IE10 and below fine thanks to Siropo, but I am not sure how to get the file to load before the rest of the page.. Like I need to check if the browser is IE10 and below, and then load the file in with everything else. Is there maybe a way to tell everything to wait until I've checked browser type?

解决方案

If you only need to detect different versions of IE and not other browsers, you could go for the IE specific HTML conditionals:

http://www.sitepoint.com/web-foundations/internet-explorer-conditional-comments/

If you are using a framework to build your site that supports some sort of templating system, you could rely on the User-Agent in the request to render different HTML templates for different browsers.

这篇关于基于浏览器加载不同的HTML文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 01:36