Last active
          March 1, 2022 12:41 
        
      - 
      
- 
        Save tarun/4390746 to your computer and use it in GitHub Desktop. 
Revisions
- 
        tarun revised this gist Dec 27, 2012 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,6 +11,8 @@ <h1>Parent</h1> <ol id="info-panel"> </ol> <button id="post-message-local">postMessage locally</button> <button id="dummy-button">Dummy Button</button> <script type="text/javascript" src="trace.js"></script> @@ -27,6 +29,10 @@ <h1>Parent</h1> test.log('dummy button pressed'); }); document.getElementById('post-message-local').addEventListener('click', function() { window.postMessage('test-local-timeout at ' + (new Date()).toLocaleTimeString(), '*'); }); window.addEventListener('message', function(e) { var delay = 1000; var index = ++i; 
- 
        tarun created this gist Dec 27, 2012 .There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,58 @@ <!DOCTYPE html> <html> <head> <title>iOS background setTimeout test - parent</title> </head> <body> <h1>Parent</h1> <button id="open-popup">Open Popup</button> <ol id="info-panel"> </ol> <button id="dummy-button">Dummy Button</button> <script type="text/javascript" src="trace.js"></script> <script type="text/javascript"> (function() { var i = 0; /* doing this as browsers will block opening popups if not initiated by user action */ document.getElementById('open-popup').addEventListener('click', function() { window.open('popup.html', 'test-popup', 'width=400,height=400'); }); document.getElementById('dummy-button').addEventListener('click', function() { test.log('dummy button pressed'); }); window.addEventListener('message', function(e) { var delay = 1000; var index = ++i; var intervalId = 0; var intervalCount = 0; var messageInfo = "parent setCallback index :" + index + ", for popup message " + e.data + ", using delay " + delay; test.log(e); test.log('settingTimeout for ' + messageInfo); setTimeout(function() { test.log(' in Timeout callback ' + messageInfo); }, delay); test.log('settingInterval ' + messageInfo); intervalId = setInterval(function() { test.log(' in Interval callback with count ' + intervalCount + ', ' + messageInfo); intervalCount++; if (intervalCount > 2) { clearInterval(intervalId); } }, delay); }); }()); </script> </body> </html> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ <!DOCTYPE html> <html> <head> <title>iOS background setTimeout test - child</title> </head> <body> <h1>Child</h1> <ol id="info-panel"> </ol> <script type="text/javascript" src="trace.js"></script> <script type="text/javascript"> (function() { var delay = 1000; test.log('will post mesage in ' + delay + ' milli-seconds'); setTimeout(function() { test.log('posting message'); window.opener.postMessage('test-parent-timeout at ' + (new Date()).toLocaleTimeString(), '*'); }, delay); }()); </script> </body> </html> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ (function() { var test = window.test; if (typeof test === "undefined") { test = {}; } var infoPanel = document.getElementById('info-panel'); test.log = function(message) { var li = document.createElement('li'); var now = "[ " + (new Date()).toLocaleTimeString() + " ]"; var logMessage = ""; li.innerHTML = now + "\t" + message; infoPanel.appendChild(li); if (typeof message === "string") { console.log(now + "\t" + message); } else { console.log(now); console.log(message); } }; window.test = test; }()); (function() { test.log('loaded'); }());