Search code examples
javascriptbookmarkletbookmarks

How to create a browser bookmark that opens in a new window by default?


I'm trying to create a bookmarlet that always opens in a new tab without requiring the user to ctrl-click or right-click the bookmarklet. (Firefox/Chrome)

I tried this:

javascript:window.open('https://google.com');

and it sort of works: it opens Google in a new tab, but then the current tab's address bar is replaced with the bookmark code, and the current tab's body becomes [object Window].

If I append window.history.back(); to the bookmarklet, it actually goes back to the page before the current one.

Any ideas?


Solution

  • Sometimes you get weird bookmarklet behavior when you don't close the document. Try this:

    javascript:var w=window.open();w.location='https://www.google.com';w.document.close();
    

    It worked in chrome. I don't have Firefox.