简体   繁体   中英

How to check which HTML is being used from JavaScript file?

I am using one JavaScript file for multiple HTML files, but I don't want a certain part of the JavaScript file to be used for one of the HTML files. How do I check which HTML file is being used?

您可以使用window.location获取url并解析结果并处理这种情况。

You can use window.location to get the current URL.

But, really, I think a better approach would be to have some argument or setting to activate or disable functionality. That would give you more flexibility in the long run.

One easy way is to pass parameters to the javascript. Look at this answer
you can also use globals, but parameters are cleaner and safer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM