简体   繁体   English

如何强制每个页面加载特定的javascript文件?

[英]How to force every page to load a certain javascript file?

I've created a pretty basic system here at work that does what Google analytics does (extremely simplistic in comparison) and it works quite well, but like Google Analytics it requires each page to reference a JavaScript file. 我在这里已经创建了一个非常基本的系统,可以完成Google Analytics(分析)的工作(相比之下极其简单),并且运行良好,但是像Google Analytics(分析)一样,它要求每个页面都引用一个JavaScript文件。 Is there any way to make all of our pages that are served from IIS reference this Javascript file? 有什么方法可以使IIS提供的所有页面都引用此Javascript文件? I would like to capture these stats for every page. 我想捕获每个页面的这些统计信息。

Any ideas? 有任何想法吗?

Thanks 谢谢

If you're dealing with static HTML files your best bet seems to be this previous question . 如果您要处理静态HTML文件,那么最好的选择似乎是上一个问题

If you have an ASP site going, and you already have a header or layout file, I'd recommend putting it in there. 如果您有一个ASP网站,并且已经有头文件或布局文件,则建议将其放在其中。

This depends on how you build your web site, but most people do this by adding the reference to their templates, layouts, master pages, or whatever term is used in your development platform. 这取决于您构建网站的方式,但是大多数人通过在其模板,布局,母版页或开发平台中使用的任何术语上添加引用来实现此目的。

You don't want every page tracked, eg, pages returning data such as JSON or XML should not be meddled with. 您不希望跟踪每个页面,例如,不应干扰返回数据(例如JSON或XML)的页面。 This is why it is better to have explicit control over which pages get the analytics javascript added to them. 这就是为什么最好对要向其添加分析javascript的页面进行明确控制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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