最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Javascript, delete the last item in history (firefox addon) - Stack Overflow

matteradmin5PV0评论

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.

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 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.

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);


            }
Share Improve this question edited Dec 4, 2013 at 10:18 BenMorel 36.7k52 gold badges206 silver badges337 bronze badges asked Jun 28, 2011 at 12:00 RyanRyan 10.1k23 gold badges68 silver badges103 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

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. Instead you should use window.location.replace(...) which will "replace" the current page without creating an additional history entry.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far