Below we introduce a simpler method through this example:
We save the statistical code to a file: File path:/config/counter.conf
The statistical code is as follows:
We use StreamReader to convert the file The content is read out, and the code will not be listed in detail
We need a page to output this javascript code:
Page:/do.ashx?args=GetCounter
string code = "Read statistical code";
code = Regex. Replace(code, "[']",""");
code = Regex.Replace(code, "[nr]", "");
context.Response.Write("document.write( '" code "');");
In this way, the output javascript can be added to the page to achieve statistical functions!
We only need to reference the javascript file on the web page Add the following code:
var _s=document.createElement( 'script');
_s.type='text/javascript';
_s.src='/do.ashx?args=GetCounter';
var _fs=document.getElementsByTagName("script") [0];
_fs.parentNode.insertBefore(_s,_fs);
You’re done, the statistics code will not be displayed in your webpage, but it has actually been loaded into your webpage !
Statement: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