Home > Backend Development > PHP Tutorial > javascript - js文件如何获取谁引用了自己?

javascript - js文件如何获取谁引用了自己?

WBOY
Release: 2016-06-06 20:18:33
Original
1513 people have browsed it

假设我有一个 a.html ,然后里面
再然后我还有个b.html ,里面也引用了 xx.js
那么xx.js该如何分辨是谁引用了自己?
除了在引用地址上传递参数之外,还有别的办法吗?

回复内容:

假设我有一个 a.html ,然后里面
再然后我还有个b.html ,里面也引用了 xx.js
那么xx.js该如何分辨是谁引用了自己?
除了在引用地址上传递参数之外,还有别的办法吗?

<code>location.href</code>
Copy after login

你可以在a.html里定义一个变量 var page_name = a; b.html 定义变量 var page_name = b;
此时你可以在需要引用的xx.js 获取到page_name,根据a,b值来进行你的逻辑判断

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template