打开外部链接而不中断元自动刷新

时间:2017-03-28 00:57:49

标签: javascript html refresh

我有一个非常基本的teampeak查看器网站,显示当前的用户。

我正在使用此自动刷新标记:

<meta http-equiv="refresh" content="60;url=index.html">

我有一个连接到点击的Teamspeak服务器的按钮:

<a href="ts3server://server.address?port=9999" class="ui-btn ui-corner-all ui-shadow">Connect To This TeamSpeak</a>

所有工作都很棒,除了当我点击打开Windows应用程序的按钮时,互联网页面每隔60秒停止刷新一次。

我对这一切都很陌生,非常感谢任何帮助!

2 个答案:

答案 0 :(得分:0)

尝试将target="_blank"添加到按钮的代码中,这将使其在新标签中打开链接,然后转移到Teamspeak应用程序。这样可以防止它对自动刷新产生任何干扰。

答案 1 :(得分:0)

好的,我明白了。我删除了html meta:

<meta http-equiv="refresh" content="60;url=index.html">

并修改了我从Philip M. 2010中找到的Javascript代码:

<script type = "text/javascript">
/*author Philip M. 2010*/

var timeInSecs;
var ticker;

function startTimer(secs){
timeInSecs = parseInt(secs)-1;
ticker = setInterval("tick()",1000);   // every second
}

function tick() {
var secs = timeInSecs;
if (secs <5 ) {
document.getElementById("countdown").style.color = "red";  // and any other styling desired
}
if (secs>0) {
timeInSecs--;
}
else {
document.location.reload(true)
//clearInterval(ticker); // stop counting at zero
// startTimer(60);  // remove forward slashes in front of startTimer to repeat if required
}

document.getElementById("countdown").innerHTML = secs;
}

startTimer(60);  // 60 seconds 

</script>

<span id="countdown" style="font-weight: bold;">60</span>

我修改的部分是:

else {
document.location.reload(true)

现在,如果我点击按钮启动外部Windows应用程序,页面仍会每60秒刷新一次。

相关问题