OLD | NEW |
---|---|
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <title>Geolocation</title> | 4 <title>Geolocation</title> |
5 <script> | 5 <script> |
6 var positionCount = 0; | 6 var positionCount = 0; |
7 | |
7 function gotPos(position) { | 8 function gotPos(position) { |
8 positionCount++; | 9 positionCount++; |
9 window.document.title = 'Count:' + positionCount; | 10 window.document.title = 'Count:' + positionCount; |
10 } | 11 } |
11 function errorCallback(error){ | 12 function errorCallback(error){ |
12 window.document.title = 'deny'; | 13 window.document.title = 'deny'; |
13 console.log('navigator.getCurrentPosition error: ', error); | 14 console.log('navigator.getCurrentPosition error: ', error); |
14 } | 15 } |
15 function initiate_getCurrentPosition() { | 16 function initiate_getCurrentPosition() { |
16 navigator.geolocation.getCurrentPosition( | 17 navigator.geolocation.getCurrentPosition( |
17 gotPos, errorCallback, { }); | 18 gotPos, errorCallback, { }); |
18 } | 19 } |
19 function initiate_watchPosition() { | 20 function initiate_watchPosition() { |
20 navigator.geolocation.watchPosition( | 21 navigator.geolocation.watchPosition( |
21 gotPos, errorCallback, { }); | 22 gotPos, errorCallback, { }); |
22 } | 23 } |
24 | |
25 // The modal permission dialog requires a user gesture to trigger. H ook up | |
26 // a click event listener to run a specified method (which may be ch anged by | |
lshang
2016/11/01 03:47:44
wrap lines to 80-column limit
dominickn
2016/11/01 04:44:00
Done.
| |
27 // the test). | |
28 var functionToRun = 'initiate_getCurrentPosition()'; | |
29 function runFunctionOnClick() { | |
30 eval(functionToRun); | |
31 } | |
32 | |
33 window.addEventListener('load', () => { | |
34 window.addEventListener('click', runFunctionOnClick); | |
35 }); | |
23 </script> | 36 </script> |
24 </head> | 37 </head> |
25 <body> | 38 <body> |
26 </body> | 39 </body> |
27 </html> | 40 </html> |
OLD | NEW |