0

Is it possible to add an external js file based on domain name from integration ?

Lets say the domain is: example.com. When user installs my integration, I want to add a myintegration.com/examplecom.js to my magento store.

1

2 Answers 2

1

Use this in your default.xml:

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <script src="http://myintegration.com/examplecom.js" src_type="url" />
    </head>
</page>
1
  • I don't have a default.xml and the script name should be generated with php depending on the domain name. I can't use php in xml. Commented Jul 31, 2017 at 10:38
0

I didn't try it but I think you can do this with require. In the requirejs-config.js of your module you can do something like:

var domain = window.location.hostname,  
    jsPath = 'myintegration.com/' + domain.match(/(?:http?:\/\/)?(?:www\.)?(.*?)\//) + '.js';

var config = {
    "paths": {
            "myintegration": jsPath
    }
};

(Indicative code, not tested)

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.