javascript 新页面加载时间

发布于 2024-10-07 10:56:05 字数 319 浏览 0 评论 0原文

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

我这里有一个按钮

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

和一个功能

问题:当我按下按钮时,我应该启动一个计时器,当页面完全加载时计时器将停止..

我需要什么时候按下按钮? 当页面完全加载时?

我该怎么办?

<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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不一样的天空 2024-10-14 10:56:05

如果你会使用 jQuery 那么我会推荐这个插件
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
}

然后在“子”窗口中,我相信这样的事情应该有效吗?
但我猜测只有当父母和孩子位于同一域时这才有效

jQuery(document).ready(function () {
    // call js method that lives on the parent window
    window.opener.stopTimer(); 
});

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(); 
});
残月升风 2024-10-14 10:56:05

注意:以下 scURIple(与 javascript: scriplets 相对应的通用 URI)是无状态的,因此不受发起策略的限制。

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>

数值结果以毫秒为单位。

适用相同站点来源和跨站点脚本策略。例如,如果uri='http://www.google.com',则上面的页面必须加载到已显示来自 www.google.com 的页面的窗口中>。

测试使用:

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)

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文