Include JS Functions Library in JS File
Forum rules
iMacros EOL - Attention!
The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.
Thank you again for your business and support.
Sincerely,
The Progress Team
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
iMacros EOL - Attention!
The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.
Thank you again for your business and support.
Sincerely,
The Progress Team
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Include JS Functions Library in JS File
I have many macros written in javascript, and most of them use the same custom functions that I have written. As such, I want to have just 1 single js functions library file and call that from each of my macro scripts so as to not duplicate code. I know there is no native way to include files within .js and nothing I have tried as worked to append two .js files.
I'm sure this is something that someone else using iMacros has asked themself, so how do I do this?
I'm sure this is something that someone else using iMacros has asked themself, so how do I do this?
Re: Include JS Functions Library in JS File
For my scripts I load them using the the eval function.
For example to load jQuery:
I have only used this technique to load scripts that are hosted somewhere and are web accessible. You might be able to do this using a URL to a local file but I have not tried that.
If you need somewhere to host your scripts you can always make a GitHub repository containing your scripts. Then on the GitHub website click the link to the "raw" version of you .js file and copy the URL
For example to load jQuery:
Code: Select all
loadScriptAtURL('https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js');
if (!jQuery) {
throw new Error('jQuery failed to load');
}
$.ajaxSetup({
async: false
});
/**
* Function to load a generic script at the specified URL
*/
function loadScriptAtURL(url) {
var request = new XMLHttpRequest();
var async = false;
request.open('GET', url, async);
request.send();
// because of "false" above, will block until the request is done and status
// is available. Not recommended, however it works for simple cases.
if (request.status !== 200) {
var message = 'an error occurred while loading script at url: ' + url +', status: ' + request.status;
iimDisplay(message);
return false;
}
eval(request.response);
return true;
}
If you need somewhere to host your scripts you can always make a GitHub repository containing your scripts. Then on the GitHub website click the link to the "raw" version of you .js file and copy the URL
Re: Include JS Functions Library in JS File
I uploaded my functions library and changed the url in the code you provided. I added the code to a test script on my computer but I am unable to call any of my functions from my functions library that I uploaded to my server.
Re: Include JS Functions Library in JS File
What debugging have you done? Does request.response have any text in it? Try doing an
You might have to change request.response to request.responseText
Can you load jQuery and calls it's functions?
Code: Select all
alert("request response: " + request.response);
Can you load jQuery and calls it's functions?
Re: Include JS Functions Library in JS File
I get the following error when running the script (all it does is call the remote functions library).
ReferenceError: jQuery is not defined (Error code: 991)
If I remove the if (jQuery...) statement, I get the following error.
ReferenceError: request is not defined (Error code: 991)
ReferenceError: jQuery is not defined (Error code: 991)
If I remove the if (jQuery...) statement, I get the following error.
ReferenceError: request is not defined (Error code: 991)
Re: Include JS Functions Library in JS File
just simply use the method component import, sample :
Define your javascript module and name it with my_module.jsm for example (.js extension does not work, dunno why)
function test_module() {
return "Test Module";
}
In your running my_test.js file, you need to reference to your module .jsm stored on the disk :
Components.utils.import("file:///C:/My_Path/my_module.jsm");
alert(test_module());
Define your javascript module and name it with my_module.jsm for example (.js extension does not work, dunno why)
function test_module() {
return "Test Module";
}
In your running my_test.js file, you need to reference to your module .jsm stored on the disk :
Components.utils.import("file:///C:/My_Path/my_module.jsm");
alert(test_module());
Re: Include JS Functions Library in JS File
I get an error returned:
Code: Select all
Error: file:///C:/My_Path/my_module.jsm - EXPORTED_SYMBOLS is not an array. (Error code: 991)
Re: Include JS Functions Library in JS File
I changed the url and got error:ReferenceError: geoip_country_code is not defined (Error code: 991)
Code: Select all
loadScriptAtURL('http://j.maxmind.com/app/geoip.js');
alert(geoip_country_code());
soma wrote:For my scripts I load them using the the eval function.
For example to load jQuery:I have only used this technique to load scripts that are hosted somewhere and are web accessible. You might be able to do this using a URL to a local file but I have not tried that.Code: Select all
loadScriptAtURL('https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'); if (!jQuery) { throw new Error('jQuery failed to load'); } $.ajaxSetup({ async: false }); /** * Function to load a generic script at the specified URL */ function loadScriptAtURL(url) { var request = new XMLHttpRequest(); var async = false; request.open('GET', url, async); request.send(); // because of "false" above, will block until the request is done and status // is available. Not recommended, however it works for simple cases. if (request.status !== 200) { var message = 'an error occurred while loading script at url: ' + url +', status: ' + request.status; iimDisplay(message); return false; } eval(request.response); return true; }
If you need somewhere to host your scripts you can always make a GitHub repository containing your scripts. Then on the GitHub website click the link to the "raw" version of you .js file and copy the URL
Re: Include JS Functions Library in JS File
Anybody found solution?
Re: Include JS Functions Library in JS File
same problem here when using
I get this error:
Am I missing something?
Code: Select all
Components.utils.import("file:///C:/my_module.jsm");
I can't believe that a 12-year automation software, 5-year firefox addon don't have the ability to #include javascript .js files.Error: file:///C:/my_module.jsm - EXPORTED_SYMBOLS is not an array. (Error code: 991)
Am I missing something?
Re: Include JS Functions Library in JS File
same problem for me
Re: Include JS Functions Library in JS File
Is this a limitation in Firefox XUL environment?
Re: Include JS Functions Library in JS File
I would really like to be able to include custom user functions from some library folder, and the ability to use jQuery selectors and traversing without calling .iim every time.
Thank you.
Thank you.
Re: Include JS Functions Library in JS File
Hello,
I think I may have found something helpful for this scenario. Although to be honest, I'm rather intermediate in javascript and this seems to be more of an advanced conversation so it may be of limited use to you guys. Anyway, take a look at the link below if you have a moment...
http://stackoverflow.com/questions/9500 ... 00775|a436
Regards,
Cark
I think I may have found something helpful for this scenario. Although to be honest, I'm rather intermediate in javascript and this seems to be more of an advanced conversation so it may be of limited use to you guys. Anyway, take a look at the link below if you have a moment...
http://stackoverflow.com/questions/9500 ... 00775|a436
Regards,
Cark
Re: Include JS Functions Library in JS File
The topic at stackoverflow is about including javascript to the page - .createElement('script') method is about adding <script></script> tag to the page in the DOM.
The js functions, variables are not available to the imacros firefox javascript
The js functions, variables are not available to the imacros firefox javascript