I am developing a jQuery plugin which needs to load other files relative to the same directory in which my ‘plugin.js’ file is located. Is there a way to do this?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
One way to achieve this is to loop through all
$('script')elements, identify the one that represents your plugin inclusion, and extract the path. Of course this might not be reliable as the consumer of your plugin might have renamed your.jsfile.Actually what you have is a pretty weird requirement. Can’t you simply describe in the documentation of the plugin which scripts need to be included or simply pass the relative url as argument to your plugin? For example many jQuery plugins take a url as parameter so that the consumer can specify where did he put other required scripts. This allows for the consumer more flexibility on the location of those external scripts.