如何使用布局XML在Magento2中添加/删除浏览器特定的JS和CSS


Answers:




9

您可以添加特定于浏览器的CSS,如下所示:

<page>   
<head>
        <css src="css/ie-9.css" ie_condition="IE 9" />
    </head>
</page>

您可以删除js和CSS,如下所示:

    <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
   <head>
        <!-- Remove local resources -->
        <remove src="css/styles-m.css" />
        <remove src="my-js.js"/>
        <remove src="Magento_Catalog::js/compare.js" />

    <!-- Remove external resources -->
        <remove src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css"/>
        <remove src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"/>
        <remove src="http://fonts.googleapis.com/css?family=Montserrat" /> 
   </head>

请参考官方文档:http : //devdocs.magento.com/guides/v2.0/frontend-dev-guide/layouts/xml-manage.html#layout_markup_css


嗨@Pramod,如何仅为野生动物园浏览器添加CSS?
贾法尔·品哈尔(Jafar Pinjar)

3

用于从主页cms删除js文件。

我们需要包含cms_index_index.xml文件是我们的自定义主题,通过使用此布局文件,可以删除magento 2主页中的js文件。示例在这里-

<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
     <remove src="varien/form.js"/>
    </head>
</page>
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.