简体   繁体   English

防止加载第二个静态HTML页面

[英]Preventing second static HTML page from loading

I have a link on a page. 我在页面上有一个链接。 When the user clicks the link a static HTML page loads. 当用户单击链接时,会加载静态HTML页面。 I would like to prevent the user from launching a second instance of the same static HTML document. 我想阻止用户启动相同静态HTML文档的第二个实例。

I'm thinking some javascript up front in the static HTML page might do. 我想在静态HTML页面中可能会有一些javascript。 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). 基本上,如果脚本检测到已经加载了静态HTML文档的实例,则Javascript弹出窗口将向用户指示“文档已经加载”(类似的情况)。

Anyhow, Java script is not my strong point so wondering if someone can please shed some light on this. 无论如何,Java脚本不是我的强项,所以想知道是否有人能够对此有所了解。

I'm not sure if this is cross-browser, but works in Chrome: 我不确定这是否是跨浏览器,但适用于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 http://jsbin.com/ivabax/1/edit

You could implement a logging feature that tracks each link that was clicked and maintains a session for the current user. 您可以实现一个日志记录功能,该功能可跟踪单击的每个链接并维护当前用户的会话。 If the link has already been clicked then you could present your firewall window that says "Sorry, this link has already been accessed". 如果已单击该链接,则可以显示防火墙窗口,其中显示“抱歉,此链接已被访问”。

So the hyperlink the user would click would first hit a tracking mechanism before being allowed (or not allowed) to continue to the URL in question. 因此,在允许(或不允许)继续到相关URL之前,用户将点击的超链接将首先点击跟踪机制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM