Getting URL of executing JavaScript file (IE6-7 problem mostly)

前端 未结 2 1967
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-15 19:27

Hey all, I\'ve been trying to throw together a generic function that retrieves the absolute URL of an executing JavaScript file on a web page:

http://gist.github.com

2条回答
  •  感情败类
    2020-12-15 19:58

    Sorry, I suspect you might struggle with this. IE earlier than version 8 typically gives error messages from javascript errors of the form:

    line: 342
    char: 3
    error: expected identifier, string or number
    code: 0
    url: http://example.com/path/to/resource
    

    where the url is the window.location.href, rather than the URL of the external Javascript resource that contains the problem. I suggest that IE gives the unhelpful URL value since the script URL isn't available to IE at that point, and neither is it available to any Javascript you might write to try to display it.

    I would love to be able to link to IE8 release notes which say this bug / feature has been fixed, hence the reason I created this as community wiki. My MSDN foo is pretty weak!

提交回复
热议问题