How can I find out the URL of the JS file that was called?

如何查找被调用的JS文件的URL ?

Let's say the JS file (which is part of a library) and the HTML file (which is the application) are on a different server. To find out the URL of the HTML file is easy. But how can I find out the server name and path of the JS files' server within the JS file itself? (Edit: There is a loader which invokes other JS files of thsi library in the same directory structure)

假设JS文件(它是一个库的一部分)和HTML文件(应用程序)在不同的服务器上。查找HTML文件的URL很容易。但是如何在JS文件本身中找到JS文件服务器的服务器名和路径呢?(编辑:有一个加载程序在相同的目录结构中调用thsi库的其他JS文件)

Preferably a JQuery or pure JS solution.

最好是JQuery或纯JS解决方案。

Edit:

编辑:

After I learned from your answers and comments I decided it would be cleaner to actually move the loader code to the first server, where also the html lives, which avoids the problem.

在我从您的回答和评论中了解到之后,我决定将加载程序代码移动到第一个服务器(也就是html所在的服务器),这样可以避免这个问题。

2 个解决方案

#1


4

In JQuery you could do:

在JQuery中你可以做到:

$('script').each(function(i, e) {
    alert($(e).attr('src'));
});

更多相关文章

  1. 如何使用Angular.js从json文件中使用id获取特定数据
  2. 如何从一个节点生成exe文件。js应用?
  3. 客户端处理和服务器端处理,哪个比较快?
  4. 在批处理文件中使用JSMin
  5. 使用HTML文件中的React调用.js文件中的Javascript函数
  6. 返回JsonResult会导致500内部服务器错误
  7. 在JavaScript中进行文件处理,第四部分:对象URLs
  8. [转]在网页中加入声音文件,并且用JavaScript对其进行播放控制
  9. 从服务器(任何服务器)获取当前日期和时间。仅限javascript

随机推荐

  1. 丢失android系统库或Conversion to Dalvi
  2. 用Xamarin 实现园友的 :Android浮动小球与
  3. Android 开机log以及常见异常
  4. Android(安卓)Eventbus控件发送与接收
  5. android中解析文件的三种方式
  6. Android数据库升级
  7. Android下uid与多用户释疑(一)
  8. Android(安卓)源码解析 - ScrollView
  9. android的init实例
  10. Android 原生页面同H5交互