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

javascript - Modernizr help? - Stack Overflow

programmeradmin7浏览0评论

I can't seem to get modernizr to work on my website. I have added the javascript files into a folder and called to them. I've also added no-js to the html but still nothing.

When I view source, it doesn't populate the html like it should.

I'm not using it for css3 elements yet so I don't need any fallback styles, I just want to be able to use the more semantic tags like header, nav, footer etc...

This is my document code:

<!DOCTYPE html>

<html class="no-js" lang="en">
<head>
    <meta charset=utf-8>
    <title></title>
    <!--[if IE]>
    <script src=".js">
    </script>
    <![endif]-->

    <script type="text/javascript" src="/js/modernizr-1.7.min.js"></script>

I can't seem to get modernizr to work on my website. I have added the javascript files into a folder and called to them. I've also added no-js to the html but still nothing.

When I view source, it doesn't populate the html like it should.

I'm not using it for css3 elements yet so I don't need any fallback styles, I just want to be able to use the more semantic tags like header, nav, footer etc...

This is my document code:

<!DOCTYPE html>

<html class="no-js" lang="en">
<head>
    <meta charset=utf-8>
    <title></title>
    <!--[if IE]>
    <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js">
    </script>
    <![endif]-->

    <script type="text/javascript" src="/js/modernizr-1.7.min.js"></script>
Share Improve this question asked May 17, 2011 at 10:15 Simon HamillSimon Hamill 711 silver badge2 bronze badges 6
  • Can you provide a link to your site? are you trying to do it locally? – methodofaction Commented May 17, 2011 at 10:23
  • No, it's hosted on a server. Sorry, can't provide a link to my side unfortunately but I can post whatever code needed and edit anything. – Simon Hamill Commented May 17, 2011 at 10:32
  • 1 If you're using Modernizr, then you don't need HTML5Shiv, as Modernizr includes that functionality. See also: stackoverflow.com/questions/3855294/… – Spudley Commented May 17, 2011 at 10:51
  • 1 It doesn't show up in the view source, use firebug or chrome dev tools and you should see all the classes added to your html node. – Neil Commented Oct 27, 2011 at 13:15
  • Did Modernizr only detects what features are supported by the browser ? or Modernizr it able to add features to browser which not exist ? THx – yossi Commented Jul 20, 2012 at 5:09
 |  Show 1 more comment

4 Answers 4

Reset to default 10

Ran into this problem myself. Make sure you view the page during run-time. When you view the page source, js calls are not executed and it will not replace the no-js. If you are using Chrome then use their element inspector.

It is most likely a path issue. Try temporally replacing

<script type="text/javascript" src="/js/modernizr-1.7.min.js"></script>

With

<script type="text/javascript" src="http://ajax.cdnjs.com/ajax/libs/modernizr/1.7/modernizr-1.7.min.js"></script>

Or it could be working, but it's not obvious. Keep in mind you don't see the Modernizr classes when you view the source, you need a tool like Firebug on FF or the Developer Tools on Chrome to actually inspect the post-javascript code.

An additional test would be doing something like...

.borderradius body {
  background: #c00;
}

And if the background is red, then Modernizr is running.

You don't have any styles here but maybe you haven't defined your HTML5 elements as display: block? Modernizr doesn't do that by itself and so you still won't get the results you expect if you don't add that into your CSS.

For the record I had this issue too. After a long time testing I found that removing the 'Add CSS Classes' option from the custom build was causing it for me.

发布评论

评论列表(0)

  1. 暂无评论