Add bookmark which is javascript only and not url

I think the reason I can't do this is because it could be a huge security hole, but here it goes ...

I want to have a bookmark in my browser (preferably FF3), this is just a piece of javascript code. It would simply build the URL based on the current date and then execute window.location = on that URL.

I know that I can make a page and save it on my local machine, and just link to it that way, but I'm just wondering if you can get around this step and actually have the bookmark "location" really just JavaScript. I could have sworn it was possible many years ago, but I can’t find anything that tells me anyway.

+41
javascript bookmarks bookmarklet
Aug 12 '08 at 18:27
source share
5 answers

What you need is a bookmarklet that is easy to create and should work in most major browsers.

Edit: stack overflow does not seem to allow bookmarklets to be created in the context of the site, basically you can create a new bookmark and enter the following in the location field

  javascript: window.location = 'http: //www.google.com/search? q =' + Date () 

to get the bookmarklet that google searches for the current date.

+54
Aug 12 '08 at 18:29
source share

It's worth noting that you can put this in a function wrapper. imranamajeed beautifully illustrated this for us ... but apparently I am too new to this site to take up my post .: P

therefore, for clarity:

javascript:(function(){ location.href = location.href + "#"; })(); 

(carriage return does not affect performance in Chrome and IE)

+19
Jul 20 2018-11-17T00:
source share

One small catch. IE can only process 508 characters in this format. If you save it in IE with a longer URL, it will be truncated without warning and thus will work.

If you need a really complex script, you will need to use a “hosted” bookmarklet, in which you have a small bookmark that introduces a script tag to the page to “call” your hosted bookmarklet.

This is not so nice / portable, but it is the only workaround.

+11
Sep 16 '08 at 1:57
source share

Google bookmark

 javascript:(function(){var%20a=window,b=document,c=encodeURIComponent,d=a.open("http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk="+c(b.location)+"&title="+c(b.title),"bkmk_popup","left="+((a.screenX||a.screenLeft)+10)+",top="+((a.screenY||a.screenTop)+10)+",height=420px,width=550px,resizable=1,alwaysRaised=1");a.setTimeout(function(){d.focus()},300)})(); 
+9
Jan 24 '09 at 20:13
source share

Well, I just created a bookmark in FF3, came back and updated it and added the following test:

 javascript:alert('Wacky%20test%20yo'); 

Low and now, after I saved and loaded, I was able to get a warning.

I am sure you can handle something similar for your needs.

+8
Aug 12 '08 at 18:31
source share



All Articles