Dynamic title setting in Javascript

Source: Internet
Author: User
The JS Code is directly written on the master page of Asp.net. The principle is to directly extract the text value of the last element from the "navigation" code of the Web document. 1 // <! [CDATA [
2 (function (){
3 window. addeventlistener? Window. addeventlistener ('load', titleload, false): window. attachevent ('onload', titleload );
4 If (! Document. getelementbyid) return;
5 function titleload (){
6 var otextobj = Document. getelementbyid ('lastnode ');
7 if (! Otextobj) return;
8 stext = otextobj. innerhtml;
9 If (! Stext) return;
10 Document. Title = 'butterfly tree-'+ stext;
11}
12 }());
13 //]>

For HTML code, see "proficient in HTML" 6.4 semantic navigation.
The preceding method has semantics.

Practical application:

Http://demo.idea-source.net/baicheng/cn/index/

The following method is not colloquial:
The sitemappath Server Control in. NET 2.0 generates a span without semantics. 1 // <! [CDATA [
2 (function (){
3 if (! Document. getelementsbytagname) return;
4 var spanelm = Document. getelementsbytagname ('span ');
5 If (! Spanelm) return;
6 For (VAR I = 0; I <spanelm. length; I ++ ){
7 var spanelmofspan = spanelm [I]. getelementsbytagname ('span ');
8 If (! Spanelmofspan) continue;
9 For (var j = 0; j <spanelmofspan. length; j ++ ){
10 spanelmofspan [spanelmofspan. Length-1]. ID = 'lastnode ';
11}
12
13}
14 }());
15 //]>

Practical application:

Http://demo.idea-source.net/hds/cn/index/

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.