最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Vue进阶(六十三):如何使浏览器打开时,默认的文档模式就是标准模式

运维笔记admin5浏览0评论

文章目录

    • 一、前言
    • 二、IE 浏览器模式 和 文档模式的区别
    • 三、解决方法

一、前言

最近做的一个项目是基于chrome开发的,又来要求兼容ie8 ie9 ie10 ie11;那么问题来了,好多样式行为都千奇百怪的出现,后来发现,将文档模式调为标准之后,才差不多ok;那么我怎么才能确保用户打开时,文档模式是标准的呢;而且是不是ie7的标准呢?

二、IE 浏览器模式 和 文档模式的区别

1.浏览器模式

用于切换IE针对该网页的默认文档模式、对不同版本浏览器的条件备注解析、发送给网站服务器的用户代理(User_Agent)字符串的值。网站可以根据浏览器返回的不同用户代理字符串判断浏览器的版本和安装的功能,就可以向不同的浏览器返回不同的页面内容。

2.文档模式
用于指定IE的页面排版引擎(Trident)以哪个版本的方式来解析并渲染网页代码。切换文档模式会导致网页被刷新,但不会更改用户代理字符串中的版本号,也不会从服务器重新下载网页。切换浏览器模式的同时,浏览器也会自动的切换到相应的文档模式。

三、解决方法

第一步,将代码设置成html5的模式,那么用户打开项目之后,文档模式就是标准的;即不会是ie5Qurik模式;但有可能是ie7标准模式;

第二步,
2.1 在html head中写上这句代码,即可使文档模式为浏览器最高级别的模式;<meta http-equiv="X-UA-Compatible" content="IE=edge" />

2.2 若想以ie8的标准模式打开,就写成<meta http-equiv=X-UA-Compatible content=”IE=EmulateIE8“>

2.3 若想要以ie10文档模式打开,浏览器级别低于10的就以浏览器本身最高的方式打开,那么需要写这2句话(顺序不能错):

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE10">;
<meta http-equiv="X-UA-Compatible" content="IE=edge" />

原因,优先级是第一句,但第一句执行不了,再执行第二句;

注❤️:

  • Edge 模式告诉 IE 以最高级模式渲染文档,也就是任何 IE 版本都以当前版本所支持的最高级标准模式渲染,避免版本升级造成的影响。简单的说,就是什么版本 IE 就用什么版本的标准模式渲染。

    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    
  • 为防止失效,X-UA-Compatible最好紧跟在head之后,之前不要有任何不标准的标签。

注意⚠️:

  1. 若您的代码在jsp环境中,通过iframe的形式展示的,上面代码写在common.jsp或者您的basic.jsp即可;

  2. 经实践证明这句:<meta http-equiv=X-UA-Compatible content=”IE=10“>无效,必须写成IE=EmulateIE10

  3. 写多个文档模式,这样即可<meta http-equiv=”X-UA-Compatible” content=”EmulateIE8,EmulateIE10″>

发布评论

评论列表(0)

  1. 暂无评论
ok 不同模板 switch ($forum['model']) { /*case '0': include _include(APP_PATH . 'view/htm/read.htm'); break;*/ default: include _include(theme_load('read', $fid)); break; } } break; case '10': // 主题外链 / thread external link http_location(htmlspecialchars_decode(trim($thread['description']))); break; case '11': // 单页 / single page $attachlist = array(); $imagelist = array(); $thread['filelist'] = array(); $threadlist = NULL; $thread['files'] > 0 and list($attachlist, $imagelist, $thread['filelist']) = well_attach_find_by_tid($tid); $data = data_read_cache($tid); empty($data) and message(-1, lang('data_malformation')); $tidlist = $forum['threads'] ? page_find_by_fid($fid, $page, $pagesize) : NULL; if ($tidlist) { $tidarr = arrlist_values($tidlist, 'tid'); $threadlist = well_thread_find($tidarr, $pagesize); // 按之前tidlist排序 $threadlist = array2_sort_key($threadlist, $tidlist, 'tid'); } $allowpost = forum_access_user($fid, $gid, 'allowpost'); $allowupdate = forum_access_mod($fid, $gid, 'allowupdate'); $allowdelete = forum_access_mod($fid, $gid, 'allowdelete'); $access = array('allowpost' => $allowpost, 'allowupdate' => $allowupdate, 'allowdelete' => $allowdelete); $header['title'] = $thread['subject']; $header['mobile_link'] = $thread['url']; $header['keywords'] = $thread['keyword'] ? $thread['keyword'] : $thread['subject']; $header['description'] = $thread['description'] ? $thread['description'] : $thread['brief']; $_SESSION['fid'] = $fid; if ($ajax) { empty($conf['api_on']) and message(0, lang('closed')); $apilist['header'] = $header; $apilist['extra'] = $extra; $apilist['access'] = $access; $apilist['thread'] = well_thread_safe_info($thread); $apilist['thread_data'] = $data; $apilist['forum'] = $forum; $apilist['imagelist'] = $imagelist; $apilist['filelist'] = $thread['filelist']; $apilist['threadlist'] = $threadlist; message(0, $apilist); } else { include _include(theme_load('single_page', $fid)); } break; default: message(-1, lang('data_malformation')); break; } ?>