scroll-to-anchor-name.html (1615B)
1 <!doctype html> 2 <title>Fragment Navigation: scroll to anchor name is lower priority than equal id</title> 3 <meta name=timeout content=long> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <body> 7 <div></div> 8 <a name="anchor1" style="position:absolute; top:200px;"></a> 9 <div id="id-equals-anchor" style="position:absolute; top:300px;"></div> 10 <a name="id-equals-anchor" style="position:absolute; top:400px;"></a> 11 <a name="§1" style="position:absolute; top:400px;"></a> 12 <div style="height:200em;"></div> 13 <script> 14 var steps = [{ 15 fragid:'anchor1', 16 handler: function(){ 17 assert_equals( scrollPosition(), 200 ); 18 } 19 },{ 20 fragid:'id-equals-anchor', 21 handler: function(){ 22 // id still takes precedence over anchor name 23 assert_equals( scrollPosition(), 300 ); 24 } 25 },{ 26 fragid:'§1', 27 handler: function(){ 28 assert_equals( scrollPosition(), 400 ); 29 } 30 }]; 31 32 function scrollPosition(){ 33 return document.documentElement.scrollTop || document.body.scrollTop; 34 } 35 36 function runNextStep(){ 37 if( steps.length > 0 ) { 38 var step = steps.shift(); 39 var listener = t.step_func( function(){ 40 step.handler(); 41 runNextStep(); 42 }); 43 scrollToFragmentThenDo( step.fragid, listener ); 44 } else { 45 t.done(); 46 } 47 } 48 49 function scrollToFragmentThenDo( fragid, then ){ 50 location.hash = fragid; 51 setTimeout( then, 1 ); 52 } 53 54 var t = async_test(); 55 t.step( function(){ 56 assert_equals(location.hash, "", "Page must be loaded with no hash"); 57 runNextStep(); 58 }) 59 </script>