4

I have a link on a page. When the user clicks the link a static HTML page loads. I would like to prevent the user from launching a second instance of the same static HTML document.

I'm thinking some javascript up front in the static HTML page might do. Basically if the script detects that there is already an instance of the static HTML document loaded then a Javascript pop-up would indicate to the user that 'document is already loaded" (something like that).

Anyhow, Java script is not my strong point so wondering if someone can please shed some light on this.

4

2 回答 2

0

您可以实现一个日志记录功能,跟踪每个被点击的链接并为当前用户维护一个会话。如果该链接已被单击,则您可以显示防火墙窗口,显示“抱歉,此链接已被访问”。

因此,用户单击的超链接将首先点击跟踪机制,然后才被允许(或不允许)继续访问相关 URL。

于 2013-04-24T02:35:15.337 回答
0

我不确定这是否是跨浏览器,但可以在 Chrome 中使用:

var wins = {};
var anchors = document.getElementsByTagName('a');
for(var i=0, len=anchors.length; i<len; i++) {
    anchors[i].onclick = function(e) {
        e.preventDefault();
        var href = this.href;
        if(wins[href]) {
            wins[href].focus();
        } else {
            wins[href] = window.open(href);
        }

    }
}

http://jsbin.com/ivabax/1/edit

于 2012-12-19T03:22:51.080 回答