简体   繁体   中英

Dojo - Require 3rd party JS

I am using Dojo 1.6.

In one of my custom Javascript files i have the need to include another custom JS file. I do not wish to load it as a JS module or anything like that, i would just like it loading as if it was done with script tags inline..

Does anyone know how to do this?

Thanks in advance,

EDIT:

I have tried a dojo.require using the overrides for it not to check it exists etc, but it seems to want to modify paths.. I cant get it to look outside of the js folder..

EDIT:

As with alot of things it seems, now that i've written it down, i've gotten a solution.. (One i used for a similar CSS query actually)..

function require_js(href)
{
   if (typeof href == 'undefined' || href.length == 0) return false;

   var script = dojo.create("script", { src:href, type:"text/javascript" }, "");
   dojo.doc.getElementsByTagName("head")[0].appendChild(script);
}

Is there a better way of doing this?

Thanks again..

You could probably do something like

function require_js(href)
{  
   if (typeof href == 'undefined' || href.length == 0)  
       return false;  
   dojo.xhrGet({  
       url: href,  
       handleas : "javascript"  
   });   
}

This should cause it to fetch the javascript at the url and eval it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM