Forum Moderators: open
Could somebody tell me what the following script does?
To me, it seems like when there is a click in Division C, then function L is executed.
Once executed, function L sets the focus to the current window (I think) and then does something from there on.
Thanks for any help.
<script type="text/javascript">
function l(){
window.focus();
bug=new Image();
bug.src="http://www.site.com/track.php?p="+escape(document.title)+"&a="+escape(window.status);}
</script>
<div id="c" onClick="l();">....</div>
It takes advantage of the fact that when you create an Image object in javascript, and set it's src, then javascript will load that image into cache so it's available instantly.
<script type="text/javascript">
function l(){
//this is naming a global function "1"
window.focus();
//this brings this window to the forground on the client browser
bug=new Image();
//this creates an image object, though no visible picture is loaded
bug.src="http://www.site.com/track.php?p="+escape(document.title)+"&a="+escape(window.status);}
//this sets the path to the image so the browser caches the "image". What really happens is that the php page is loaded with the title of the current document and the value of the status bar (for some reason?). The php probably logs this information in a database of a log file along with the Browser,IP Address,referrer, and anything else they want.
</script>
<div id="c" onClick="l();">....</div>
this runs the function whenever the user clicks on this HTML element.
I'm not sure why they'd want the window status unless if is for debugging...
I use a similar script to log any javascript errors that a user might receive.
- JS
If an image is being requested that doesnt exist, would this result in a 404 error? Is there a better way of doing this?
Also, is "bug" some kind of standard variable, because I don't see "var bug" being set. I tried searching for something about this on Google, but "JavaScript Bug" returns lots of unwanted results.
Thanks
If an image is being requested that doesnt exist, would this result in a 404 error?
Also, is "bug" some kind of standard variable, because I don't see "var bug" being set.
Variable scope:
var b="world";//global variable
function a() {
var b = "hello";//local (does not overwrite global)
alert(b);//alerts "hello"
}
a();
alert(b);//alerts "world"
even though the function seems like it would change the value of "b", it doesn't change the global one because "var" is used inside the function.
If you took var out of the function, then the same script would alert "hello" 2 times.
- JS