2

I'm trying to add a simple js that has to be executed on documentReady with jQuery.

Script js

/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
define([
    'jquery',
    'domReady!',
], function ($) {
   //Script code
});

Also, it needs to be on a module, not a theme, on every page, adminhtml and frontend. I've tried adding the script with a default.xml like this

<?xml version="1.0"?>
<page xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <head>
        <link src="Custom_Iframe::js/iframe.js"/>
    </head>
</page>

However, this puts the script before every other script, including require-js and jQuery.

I know i can make it a module and then a block that loads the module, but i cannot understand how to do that, and i've been on the second page of google checking for answers on multiple searches.

I've also tried this answer https://magento.stackexchange.com/a/131635, but then, the script never gets loaded.

1 Answer 1

0

Please use this code in

app/design/frontend/{Vendor}/{ThemePackage}/Magento_Theme/view/default.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
    <head>
        <!-- some code-->

        <!-- for including css -->
        <css src="Magento_Theme::css/some.css"/>
        <!-- for including js -->

        <link src="Magento_Theme::js/slider/some.js"/>

        <!-- some code-->
    </head>
</page>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.