Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在加载javascript后立即使用动态加载的javascript?_Javascript_Html - Fatal编程技术网

在加载javascript后立即使用动态加载的javascript?

在加载javascript后立即使用动态加载的javascript?,javascript,html,Javascript,Html,下面是我用来在react应用程序中动态加载.js文件的代码片段 componentDidMount() { if (navigator.userAgent.indexOf('MSIE') !== -1 || navigator.appVersion.indexOf('Trident/') > -1) { const script = document.createElement('script'); script.src = '../public/w

下面是我用来在
react
应用程序中动态加载.js文件的代码片段

componentDidMount() {
    if (navigator.userAgent.indexOf('MSIE') !== -1 || navigator.appVersion.indexOf('Trident/') > -1) {
        const script = document.createElement('script');
        script.src = '../public/web/utils/flexibility.js';
        document.body.appendChild(script);

        script.onload = () => {
            // Here I want to use one of the function defined in my loaded `flexibility.js` 
            // file lets say this one flexibility(document.documentElement);

            };
        }
    }

任何关于这方面的见解都会很有帮助。

你要找的是JSONP。@Raymond我不这么认为,在上面的代码片段中也应该有这样做的方法。你要找的是JSONP。@Raymond我不这么认为,在上面的代码片段中也应该有这样做的方法。