Including a javascript relative to its own location from anotherjavascript

N

Nettar

Hello,

I want to include a javascript from another javascript.

I know that I can do that by
document.write("<script src='another.js'>");

I am exposing my main.js (which contains the above code) directly,
intending it to be used via cross-site scripting (xss).

In this case, the above code doesn't work. Because an external html
which is using my main.js will look for another.js in its local
directory.

I have to change 'another.js' to '<absolute path>/another.js' for it
to work. But now if I change the location of main.js I have to make
changes in the above code too.

Is there a way to avoid specifying the absolute path of another.js ?
I want to compute its own location in main.js and then specify the
path of another.js relative to that.

Is that possible?

Regards
Jayarama Nettar
 
T

Thomas 'PointedEars' Lahn

Nettar said:
I want to include a javascript from another javascript.

I know that I can do that by
document.write("<script src='another.js'>");

You don't know. First, the required end tag is missing. Second,
document.write() after loading overwrites the document. Third, there is no
guarantee that the markup is included, let alone a guarantee that it is
included at a certain position. Fourth, if you were to include two scripts,
you would simply write the other `script' element instead of generating it
dynamically.
I am exposing my main.js (which contains the above code) directly,
intending it to be used via cross-site scripting (xss).

In this case, the above code doesn't work. Because an external html
which is using my main.js will look for another.js in its local
directory.

It will not work for the reasons I have given above instead.


PointedEars
 
N

Nettar

You don't know.  First, the required end tag is missing.  Second,
document.write() after loading overwrites the document.  Third, there isno
guarantee that the markup is included, let alone a guarantee that it is
included at a certain position.  Fourth, if you were to include two scripts,
you would simply write the other `script' element instead of generating it
dynamically.



It will not work for the reasons I have given above instead.

PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    && navigator.userAgent.indexOf('Mac') != -1
)  // Plone, register_function.js:16

Thanks for the reply.

1. All right, I missed </script> while writing the post. I have it in
my script.
2. My main.js is included in the html in the <head>. So it will be
executed before the document completes loading.
3. I didn't get your third point. Why isn't there a guarantee that the
markup is included? In my application it is correctly included.
4. I don't want to dynamically generate the another.js. It's content
is static. What I want to change is its location, and not content.

May be you didn't get my problem. I am able to include the another.js
using document.write(). But, I want to specify its location relative
to the location of main.js.

Can someone help me on this?

Regards
Jayarama Nettar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top