Find script URL

View: New views
3 Messages — Rating Filter:   Alert me  

Find script URL

by bijumaillist :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On many JavaScript libraries one thing I noticed is the author trying
find the host/dir where the script is hosted, so that he can
dynamically add additional scripts as and when needed.

Do have something simple as navigator.scriptURL and
navigator.scriptLineNum to provide information of currently executing
script?

_______________________________________________
dev-tech-js-engine mailing list
dev-tech-js-engine@...
https://lists.mozilla.org/listinfo/dev-tech-js-engine

Re: Find script URL

by bijumaillist :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I mean, Do WE have something simple as navigator.scriptURL and
navigator.scriptLineNum to provide information of currently
executing script?

_______________________________________________
dev-tech-js-engine mailing list
dev-tech-js-engine@...
https://lists.mozilla.org/listinfo/dev-tech-js-engine

Re: Find script URL

by AJG-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

On Jul 13, 2:39 pm, biju <bijumaill...@...> wrote:
> I mean, Do WE have something simple as navigator.scriptURL and
> navigator.scriptLineNum to provide information of currently
> executing script?

As far as I know, there's no built-in object or method that does this
for you, since "document" and "window" don't exist outside of
browsers. But it's pretty easy to do it manually. Offhand, you could
do something like this (lacks error checking):

// Assumes:
JSContext* context = ...;
JSObject*   global   = ...;
const char* filename = "foo.js";

JS_DefineProperty(context, global,
    "filename", STRING_TO_JSVAL(JS_NewString(context, filename,
strlen(filename))),
    NULL, NULL, JSPROP_READONLY | JSPROP_PERMANENT));

Then, in your script, the property filename will be set to foo.js.

Hope that helps.
      Al.
_______________________________________________
dev-tech-js-engine mailing list
dev-tech-js-engine@...
https://lists.mozilla.org/listinfo/dev-tech-js-engine
LightInTheBox - Buy quality products at wholesale price