简体   繁体   English

Javascript,删除历史最后一项(firefox插件)

[英]Javascript, delete the last item in history (firefox addon)

I have a Firefox addon that first displays a warning/info page telling the user they are being redirected (chrome://localfilter/content/wait_page.html) then redirects them to their destination.我有一个 Firefox 插件,它首先显示一个警告/信息页面,告诉用户他们正在被重定向(chrome://localfilter/content/wait_page.html),然后将它们重定向到他们的目的地。

Everything is working great.一切都很好。

The only thing is when/if they press the back button they see that "wait page", is there anyway to delete just that wait page from the history and leave everything else as is?唯一的事情是当/如果他们按下后退按钮,他们看到“等待页面”,是否有从历史记录中删除那个等待页面并保留其他所有内容? Or if that is not possible replace that wait page with another page that perhaps has just the logo (because if they read they are getting redirected and nothing happens...)或者,如果这不可能,则将等待页面替换为可能只有徽标的另一个页面(因为如果他们阅读,他们将被重定向并且什么也没有发生......)

EDIT:编辑:

// function to see if the banned URL is on the list, then redirect
...
window.stop(); // Totally stop the page from loading.

                            window.content.location.href = "chrome://quickfilter/content/wait_page.html";



                            this.notificationBox();
                            self.timervar = setTimeout(function ()
                            {
                                self.main.redirectToAnotherUrl();
                            }, 2505);

...


redirectToAnotherUrl: function ()
            {


                window.content.location.href = self.mafiaafireFilterUrl;
                self.timervar = setTimeout(function ()
                            {
                                self.main.notificationBox();
                            }, 2005);


            }

Changed with replace:用替换改变:

redirectToAnotherUrl: function ()
            {


                window.content.location.replace(self.mafiaafireFilterUrl);
                self.timervar = setTimeout(function ()
                            {
                                self.main.notificationBox();
                            }, 2005);


            }

I guess that the best solution is not to delete the page from history but rather not add it in the first place.我想最好的解决方案不是从历史记录中删除页面,而是首先不添加它。 When you are "redirecting" to the target page you are probably using window.location.href =... or something like this.当您“重定向”到目标页面时,您可能正在使用window.location.href =...或类似的东西。 Instead you should use window.location.replace(...) which will "replace" the current page without creating an additional history entry.相反,您应该使用window.location.replace(...)它将“替换”当前页面而不创建额外的历史条目。

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

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