I need to add a JS script on the head tag, but only in the Success page. Inside Magento 2, I have no idea how doing this.

Someone can help me? :)

2 Answers 2

  1. create the checkout_onepage_success.xml file at following location on your custom extension


<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <script src="Vendor_Extension::js/yourcustom.js"/>
  1. now create yourcustom.js on the following location


  1. now in yourcustom.js added your code what ever you want to add.

You need to create checkout_onepage_success.xml layout in your module then adds the below code inside the page tag

    <script src="Vendor_Module::js/custom.js"/>

After that, you can create custom.js file inside your custom module.

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.