How to add script in comment on Pug ?
I have two script to include on my web page :
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
See this page in the pug docs
Pug does not have any special syntax for conditional comments. But since all lines beginning with < are treated as plain text, normal HTML style conditional comments will do fine.
So you can just use standard html for your conditional comments
Related
I want to know how can I add an asset only for IE9 in yii2 assets bundle? I mean like
<!--[if lt IE 9]>
<script src="assets/js/html5shiv.js"></script>
<script src="assets/js/respond.min.js"></script>
<![endif]-->
and another thing is how can add a js library like jquery in top of page not in the end?
You have to specify the options for your jsOptions property.
In your case, it should be something like:
public $jsOptions = ['condition' => 'lte IE9'];
Further reading:
http://www.yiiframework.com/doc-2.0/yii-web-assetbundle.html#$jsOptions-detail
and
http://www.yiiframework.com/doc-2.0/guide-structure-assets.html#asset-options
Regarding to the jQuery question, you just configure the AssetBundle's accordingly, or you can just register it in your head or wherever you want in the template inserting the normal script tag.
The following code is in head section of a page:
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
Shouldn't the comment tags stop this script from being run?
It's called Conditional Comments
https://msdn.microsoft.com/en-us/library/ms537512(v=vs.85).aspx
http://www.quirksmode.org/css/condcom.html
Only works with Internet Explorer.
IE is smart with these style comments (IE conditional comments) and knows to treat them as normal HTML.
I am getting extra text <![endif]--> in IE7 but on all other browsers does not show.
I searched this code in all files but didn't find it. I am using Drupal-7.
Please check this link here
You aren't writing those end tags correctly in some areas. Some places you put this:
<!--<![endif]-->
Change that to this:
<![endif]-->
Looks like there is an extra <![endif]--> here
<!--[if lt IE 8]>
<link type="text/css" rel="stylesheet" href="http://indivar.bubblespan.com/sites/default/files/css/css_SCgABqUC566L7vt9DqHzb_pIQdEOcwHOijyO95sLhUI.orig.css" media="all" />
<![endif]-->
<![endif]-->
Although it is difficult to tell with all the conditional comments you are using.
Better to use fewer comments and to combine content within the conditional comments as needed.
Please try to re-install conditional css module which you are using for drupal.
Is there an easy way to serve a whole stylesheet to every modern Browser but IE7 and IE8? Some kind of inverted conditional comments?
The following should work per Microsoft's documentation:
<!--[if !((IE 7)|(IE 8))]><!--><link rel="stylesheet" type="text/css" href="ie.css" /><!--<![endif]-->
I don't know much about web coding... but this looks like what you are looking for.
Check out this site.
If you are simply trying to exclude browsers older than IE9, it is simpler to use
<!--[if gte IE 9]>
<link ...
<![end if]-->
Otherwise, you will need to use other operators to fit a specific subset, as others have already provided.
The MSDN docs are very useful here: http://msdn.microsoft.com/en-us/library/ms537512(v=vs.85).aspx
Note that you can use "!" to denote "not". So you could use something like this:
<!-- [if !(IE 7) & !(IE 8)]>
<link href="modern.css" />
<![endif]-->
Pretty straight forward.
Updated
Since IE's quirky conditionals don't get respected in other browsers. You could easily add jQuery to the page and do something like this:
<script src="jquery.js"></script>
<!-- add jquery first for browser sniffing -->
<script>
// if broswer is IE and less than version 9 write out the nice CSS
if($.browser.msie && parseInt($.browser.version) < 9){
document.write("<link href='modern.css'/>");
}
</script>
jQuery docs on browser sniffing: http://api.jquery.com/jQuery.browser/
I'm just wondering if it's possible to comment out IE conditional comments themselves (for testing purposes)? The following does not work:
<!-- <!--[if IE 7]> some code <![endif]--> -->
Thanks in advance! flexx
No, it isn't possible.
SGML/HTML/XML/XHTML comments cannot be nested.
I think you can just insert something to make them invalid:
<!--\[if IE 7]> some code <!\[endif]-->
<!--[if IE 70]> some code <![endif]-->
:)
If I were you I'd use a template systems like Template Toolkit and then Just include or exclude the comment conditionally, based on some variable you could set at runtime.
Template Toolkit http://template-toolkit.org/
If you are sending that through a server such as .asp or aspx then of course you could comment that out server side.
You can't nest comments, but you can comment them out by adding an extra <!-- to the beginning. Your example from above changes from <!-- <!--[if IE 7]> some code <![endif]--> --> to <!-- <!--[if IE 7]> some code <![endif]-->. Just take out the extra --> and it should comment out that pesky conditional.
Tested successful in Firefox 3.5.2 and IE 7.0.5730.13CO