Search code examples
javascriptgoogle-chromebookmarks

Save a Bookmark which can open 2 URLs one after another


Is it possible to save a bookmark with 2 URLs ? Upon clicking on the bookmark, the first URL should be opened first and after a brief pause the second URL is opened in the same window.

E.g. First I want to open the link https://stackoverflow.com/ and after 5 seconds I want to open 2nd URL https://stackoverflow.com/questions/ask automatically in the same window.

I know we can directly open the 2nd URL but I have some dependency on 1st URL hence don't want to skip it.


Solution

  • You may use a Bookmarklet

    A bookmarklet is a bookmark stored in a web browser that contains JavaScript commands that add new features to the browser. They are stored as the URL of a bookmark in a web browser or as a hyperlink on a web page. Bookmarklets are usually small snippets of JavaScript executed when user clicks on them.

    In Javascript you may use window.open to visit urls.

    By specifying _blank as the target keyword

    _blank: usually a new tab, but users can configure browsers to open a new window instead.

    To create one, add a new bookmark pasting a code like this in the URL field:

    javascript:(function() {
        window.open('https://stackoverflow.com/', '_blank');
        setTimeout(function() {
            window.open('https://stackoverflow.com/questions/ask', '_blank');
        }, 5000);
    })();