JavaScript combines cookies to achieve browsing history 1th/3 page _javascript Tips

Source: Internet
Author: User
Tags tagname
Because of the previous understanding of JavaScript is not deep enough, a time of unprepared.
Later, after two master colleagues of the guidance (to the two colleagues of admiration like the surging river endless ... ), suddenly enlightened
The addition of this feature was successfully completed.

Let's start by introducing some of the objects and methods of this feature in javascript:

1. Window.event objects:
An event represents the state of an incident, such as the element that triggers the events object, the position and state of the mouse, the pressed key, and so on.
The event object is valid only if it occurs.

2. Event.srcelement:
Indicates the source of the event the popular point is that where the event is triggered

3. Srcelement.parentnode:
The parent node that represents the source of the occurrence of the event

4. Srcelement.tagname:
Label name that represents the source of the event occurrence

5. toUpperCase ():
How to capitalize the corresponding string

Basically these are the properties and methods that may be unfamiliar to friends who have just been in touch with JavaScript, or friends who used to use them very infrequently, but it doesn't matter, it's not hard to find out later, and the JavaScript validation form isn't much different.

The following on the combination of procedures to give you step-by-step explanation (procedures unavoidably have unreasonable place, I hope everyone will correct, common progress):

The first part: JavaScript record browsing action.
Copy Code code as follows:

function Glog (EVT)//define functions to record mouse click action
{
Evt=evt?evt:window.event;var srcelem= (evt.target)? evt.target:evt.srcElement;
Try
{
while (Srcelem.parentnode&&srcelem!=srcelem.parentnode)
The above statement determines whether the mouse action occurs in a valid area and prevents the user from being logged invalid clicks
{
if (srcelem.tagname&&srcelem.tagname.touppercase () = = "A")//Determine whether the object clicked by the user belongs to the link
{
linkname=srcelem.innerhtml; Remove the name of the event occurrence source, which is the text between <a> and <a/>, which is the name of the link.
address=srcelem.href+ "_www.achome.cn_"; Remove the href value of the event occurrence source, which is the address of the link
Wlink=linkname+ "+" +address; Consolidate the link name and link address into a variable
Old_info=getcookie ("History_info"); Retrieve history of previous records from cookies, which has a declaration
The following procedure begins to determine whether the new browsing action duplicates the previous 6 history and writes cookies if not repeated
var insert=true;
if (old_info==null)//To determine whether the cookie is empty
{
Insert=true;
}
Else
{
var old_link=old_info.split ("_www.achome.cn_");
for (Var j=0;j<=5;j++)
{
if (Old_link[j].indexof (linkname)!=-1)
Insert=false;
if (old_link[j]== "null")
Break
}
}
if (insert)
{
Wlink+=getcookie ("History_info");
Setcookie ("History_info", wlink); Write Cookie, which has a declaration behind it
History_show (). reload ();
Break
}
}
Srcelem = Srcelem.parentnode;
}
}
catch (e) {}
return true;
}
document.onclick=glog;//makes every click of the page perform the Glog function

current 1/3 page   1 23 Next read the full text
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.