On 13/11/06, henrah <[EMAIL PROTECTED]> wrote:
> Hi Sam.
>
> > That sounds like a good compromise. I've never seen that method to get
> > the current scripts file name. Does it work in most browsers (inc IE
> > 5.5+)?
>
> Actually, after  a quick trawl through MSDN, I don't think the fileName
> property on Error objects is widely supported.
>  A possible (less hacky) alternative would go something like this:
>
> new function(){
>   var scripts = document.getElementsByTagName('script'), i = 0, script,
> match;
>   while (script = scripts[i++])
>
>     if (match = /#_jq_(.*)$/.exec(
> script.src)) break;
>   window[match ? match[1] : '$'] = jQuery;
> };
>
>
> ... in this case using a prefix of _jq_ on the hash parameter, to make sure
> we are definitely seeing a jQuery script element.
>  I'd rather not have to walk the DOM to find the URL of the running script,
> but it still ought to be pretty reliable -- at least against false
> positives.

That should be more compatible than using the try..catch method and
would mean the filename you use for jQuery wouldn't matter:

<script type="text/javascript" src="jquery-latest.js#_jq_JQ"></script>
or
<script type="text/javascript" src="jquery.js#_jq_JQ"></script>
or even
<script type="text/javascript" src="elephant.js#_jq_JQ"></script>

You could even use jQuery itself to do this:

new function(){
  var match;
  jQuery("script").each( function() {
        if(match) return false;
        match = /#_jq_(.*)$/.exec(this.src);
        if (match) window[match ? match[1] : '$'] = jQuery;
  });
};

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to