mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 10:22:45 +00:00 
			
		
		
		
	 f2a28e83de
			
		
	
	
		f2a28e83de
		
	
	
	
	
		
			
			The main differences between our current implementation and the spec
are:
    * The title element need not be a child of the head element.
    * If the title element does not exist, the default value should be
      the empty string - we currently return a null string.
    * We've since added AOs for several of the spec steps here, so we
      do not need to implement those steps inline.
		
	
			
		
			
				
	
	
		
			42 lines
		
	
	
	
		
			1.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
	
		
			1.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
| <script src="include.js"></script>
 | |
| <script>
 | |
|     test(() => {
 | |
|         // The title is the empty string by default.
 | |
|         println(`1: "${document.title}"`);
 | |
| 
 | |
|         // When the title is set, and a title element does not exist, one is added to to head element.
 | |
|         let titleElements = document.getElementsByTagName('title');
 | |
|         println(`2a: ${titleElements.length}`)
 | |
| 
 | |
|         document.title = 'This is a title!';
 | |
| 
 | |
|         titleElements = document.getElementsByTagName('title');
 | |
|         println(`2b: ${titleElements.length}`)
 | |
|         println(`2c: "${titleElements[0].innerText}"`);
 | |
|         println(`2d: "${document.title}"`);
 | |
| 
 | |
|         // Removing the title element sets the title back to default.
 | |
|         titleElements[0].remove();
 | |
|         println(`3: "${document.title}"`);
 | |
| 
 | |
|         // After adding several title elements to the body, setting the title updates the text
 | |
|         // content of only the first title element.
 | |
|         document.body.appendChild(document.createElement('title'));
 | |
|         document.body.appendChild(document.createElement('title'));
 | |
|         document.body.appendChild(document.createElement('title'));
 | |
| 
 | |
|         titleElements = document.getElementsByTagName('title');
 | |
|         println(`4a: ${titleElements.length}`)
 | |
|         println(`4b: "${titleElements[0].innerText}"`);
 | |
|         println(`4c: "${titleElements[1].innerText}"`);
 | |
|         println(`4d: "${titleElements[2].innerText}"`);
 | |
| 
 | |
|         document.title = 'This is another title!';
 | |
| 
 | |
|         titleElements = document.getElementsByTagName('title');
 | |
|         println(`4e: ${titleElements.length}`)
 | |
|         println(`4f: "${titleElements[0].innerText}"`);
 | |
|         println(`4g: "${titleElements[1].innerText}"`);
 | |
|         println(`4h: "${titleElements[2].innerText}"`);
 | |
|     });
 | |
| </script>
 |