Judge whether the visitor's browser is IE6 and prompt for code upgrade

Source: Internet
Author: User

I would like to share with you a piece of code to judge the visitor's browser. This is mainly designed to "kill" IE6. We all know that IE6 has a user share of more than 50% of the world's browser shares, internet Explorer 6 is troublesome for WEB design. Therefore, each of our webmasters and bloggers is obligated to prompt visitors to upgrade Internet Explorer and discard Internet Explorer 6!

This code is intercepted in WordPress theme 8090 community template 8090st style. It may not be too complete. If your website is wordpress, install this theme directly, if your website is not a WP blog, you can also download this code to check the complete usage.

Not to mention, the above Code:

Copy to ClipboardReference: [www.bkjia.com]
$ (Function (){
$ ('Body '). append ('<div id = "hint_bg"> </div> <div id = "ie6_hint"> <span id = "close"> </span> <div id =" content_hint "> <span id =" logo "> </span> <p id =" suggest "> if you are a common user, we strongly recommend that you upgrade your browser to IE 7.0 or later to provide a better browsing experience! You can try it, but we do not recommend that you use non-IE kernel browsers, because they may cause some inconvenience to you, such as online shopping and online payment. </P> </div> <ul id = "browser"> <li class = "firefox"> <a href =" http://www.mozillaonline.com/ "Title =" upgrade to the latest version of Mozilla Firefox! "> </A> </li> <li class =" chrome "> <a href =" http://www.google.com/chrome/ "Title =" upgrade to the latest version of Google Chrome! "> </A> </li> <li class =" ie "> <a href =" http://www.microsoft.com/windows/internet-explorer/ie7/ "Title =" upgrade Microsoft IE to the latest version! "> </A> </li> <li class =" opera "> <a href =" http://www.operachina.com/ "Title =" upgrade to the latest version of Opera! "> </A> <li class =" safari "> <a href =" http://www.apple.com.cn/safari/download/ "Title =" upgrade to the latest version of Apple Safari! "> </A> </li> </ul> </div> ');

Var name = $ ('# ie6_hint ');
Var winwidth = $ (window). width ();
Var hintwidth = $ (name). width ();
Var pageheight = document. body. offsetHeight; // obtain the height of the entire webpage.
Var left = winwidth/2-hintwidth/2;
Align (name).css ({'left': left}); // center the prompt information

(('Effechint_bg'0000.css ({'opacity ': 0.5, 'height': pageheight });

Var top = $ (name). position (). top; // obtain the top value of the prompt message.

Function scrollHint (){
Var winScroll = $ (document). scrollTop (); // gets the upper and lower scrolling distance of the window.
Var newTop = winScroll + top; // obtain the top value of the information displayed after scrolling.
$ (Name). animate ({'top': newTop, 'left': left}, {duration: 800, queue: false });
}

$ (Window). scroll (scrollHint );

ScrollHint ();

Function closeHint (){
$ ('# Ie6_hint, # hint_bg'). fadeOut ();
$. Cookie ('ie6 _ hint', 'close', {expires: 48*60*60, path :'/'});
}

$ ('# Close, # hint_bg'). click (closeHint );

$ (Document). keypress (function (e ){
If (e. keyCode = 27 | e. key code = 120 | e. keyCode = 88 | e. which = 120 | e. which = 88 ){
CloseHint ();
}
});


If ($. cookie ('ie6 _ hint ')! = 'Close '){
// The cookie does not exist.
$ ('# Ie6_hint, # hint_bg'). show ();
}
Else if ($. cookie ('ie6 _ hint') = 'close '){
// The cookie exists, so no advertisement is displayed
$ ('# Ie6_hint, # hint_bg'). hide ();
}
// Downloads By http://www.bkjia.com/down

$ ('# Close'). click (closeHint );


})

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.