2
<input type="button" onclick=openAPage()></>

i have a button

function openAPage() {
var myWin = window.open("http://www.sabah.com.tr","_blank")   
}

and a function

here problem: when i press the button i should start a timer and when page fully loaded timer will stop..

i need when i pressed the button? when page fully loaded?

how should i do?

murat
  • 31
  • 3
  • What you're asking for is not possible with JavaScript, because the code that fires when the button is pressed can't get info from the page that loads. – Babiker Dec 15 '10 at 18:57

3 Answers3

0

Note: the following scURIple (generic URI counterpart to javascript: scriplets) is stateless and thus is unrestricted by origination policies.

data:text/html;charset=utf-8,
<html><script>
uri='data:text/html;charset=utf-8,<\html><\script>alert(\'click to finish load\')<\/script><\/html>';
</script>

<a href="javascript:
                      window.open(uri,'_blank') .
                              addEventListener(  'load',Function('alert(Date.now()-'+Date.now()+')'), false);">
  one  method </a><p>

<a href="javascript:st=Date.now();
                      window.open(uri,'_blank') .
                              addEventListener(  'load', function(){alert(Date.now()-st)},  false);">
 another way</a>

 </html>

The numeric results are in msec.

Same site origin and cross-site scripting policies apply. For example, if uri='http://www.google.com' then the page above must be loaded into a window already showing a page from www.google.com.

tested using:

window.navigator.userAgent=
         Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4
                                                                                                                               (Splashtop-v1.2.17.0)
ekim
  • 1
  • 1
0

Maybe this helps: Execute Javascript When Page Has Fully Loaded

Community
  • 1
  • 1
Jama A.
  • 15,680
  • 10
  • 55
  • 88
0

if you can use jQuery then I would recommend this plugin http://keith-wood.name/countdown.html

function openAPage() {
    var myWin = window.open("http://www.sabah.com.tr","_blank");
    startTimer();
}

function startTimer() {
    // ... call jquery plugin to start timer
}

function stopTimer() {
    // ... call jquery plugin to stop timer
}

then in the 'child' window, I believe something like this should work? but I am guessing this will work only if the parent and child are on the same domain

jQuery(document).ready(function () {
    // call js method that lives on the parent window
    window.opener.stopTimer(); 
});
house9
  • 20,359
  • 8
  • 55
  • 61