0

I want to have a bookmark on my browser (Firefox 3 or Chrome preferably) that is only a snippet of JavaScript code. It would construct a URL based on the current date and then do a window.location =  on that URL.

I know that I could make a page and keep it on my local machine and just refer to it that way, but I was wondering if you could bypass that step and actually have the location of the bookmark really just be JavaScript. I could have sworn that this was possible years ago, but I can't find anything that tells me either way now.

Lucas
  • 523
  • 2
  • 10
  • 20
Yuqian Lin
  • 13
  • 4

2 Answers2

1

You can do that by adding this to your favorites:

javascript:(function(){document.location.href="http://stackoverflow.com";})()

The correct name for this kind of bookmarks is favelets. For some more inspiration check out this collection of favelets.

Wim Mostmans
  • 3,485
  • 1
  • 20
  • 20
  • The 'correct name'? I've heard 'bookmarklet' used much more frequently than 'favelet'. To confirm, I looked up [the Wikipedia entry for favelet](https://en.wikipedia.org/wiki/Favelet) and found that it redirects to Bookmarklet and mentions that they represent the same thing. – Rich Moss Jul 18 '19 at 19:58
0

Use as your bookmark’s address javascript:window.location='https://www.google.com/search?q='+Date();
to create a bookmarklet that searches Google for the current date and time.

Lucas
  • 523
  • 2
  • 10
  • 20
Yuqian Lin
  • 13
  • 4