可以使用闪JavaScript的浏览器窗口? [英] Possible to flash a Browser window using Javascript?

查看:126
本文介绍了可以使用闪JavaScript的浏览器窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就像许多程序的闪存他们的任务栏/停靠窗口,以提醒用户打开程序,

Like many programs flash their window on the taskbar / dock to alert the user to switch to the program,

是否有可能闪在浏览器使用Javascript窗口?的(火狐仅脚本也欢迎)

Is it possible to flash the Browser window using Javascript? (FireFox-only scripts are also welcome)

这是基于Web的聊天/基于社区的论坛/软件那里有很多的实时活动是有益的。

This is useful for web-based Chat / Forum / Community-based software where there is lots of real-time activity.

推荐答案

@Hexagon理论:为什么你会永远改写整个头部元素只是改变一个元素在头上的价值?您的解决方案是在多个层次上效率极其低下。

@Hexagon Theory: Why would you ever rewrite the whole head element just to change the value of one element in the head? Your solution is horribly inefficient on multiple levels.

<html>
<head>
<link rel="icon" href="on.png" type="image/png" id="changeMe" />
<script type="text/javascript" src="flash.js"></script>
</head>
<body>
</body>
</html>

flash.js:

flash.js:

function Flasher(speed) {
  var elem = document.getElementById('changeMe');

  this.timer = setTimeout(function() {
    elem.href = elem.href ==  'on.png' ? 'off.png' : 'on.png';
  }, speed);

  this.stop = function() { clearTimeout(this.timer); }
}

/* sample usage
 *
 * var flasher = new Flasher(1000);
 * flasher.stop();
 */

它并没有真的要一个类,但它有助于保持全局命名空间的清洁。这是未经测试,但如果简单地改变HREF出于某种原因不能正常工作,克隆链接节点,改变href和替换克隆一个旧的链接。

It didn't really have to be a class but it helped keep the global namespace clean. That's untested but if simply changing the href doesn't work for some reason, clone the link node, change the href and replace the old link with the cloned one.

这篇关于可以使用闪JavaScript的浏览器窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆