Add a bookmark that is only javascript, not a URL

前端 未结 5 1897
傲寒
傲寒 2020-12-08 02:28

I\'m thinking that the reason I can\'t do this is because it might be a huge security hole, but here goes...

I want to have a bookmark on my browser (FF3, preferably

相关标签:
5条回答
  • 2020-12-08 02:45

    One minor catch. IE can only handle a 508 character URL in this format. If you save it in IE with a url longer than this, it will truncate without warning and thus fail.

    If you need a really complex script, you'll need to use a "hosted" bookmarklet, where you have a short bookmark that injects a script tag into the page, to "call" your hosted bookmarklet.

    It isn't as nice/portable, but its the only workaround.

    0 讨论(0)
  • 2020-12-08 02:48

    What you want is a bookmarklet they are easy to create and should work in most major browsers.

    Edit: Stack overflow seems not to allow creating bookmarklets in the context of the site, basically you can create a new bookmark and type the following in the location field

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

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

    0 讨论(0)
  • 2020-12-08 02:55

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

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

    Low and behold, after I saved and loaded, I was able to get my alert.

    I'm sure you can work up something similar for your needs.

    0 讨论(0)
  • 2020-12-08 02:57

    It is worthy of note that you can put that in a function wrapper as well. imranamajeed nicely illustrated that for us... but apparently I'm too new to the site to up his post. :P

    so for clarity:

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

    (the carriage returns did not affect performance in chrome and IE)

    0 讨论(0)
  • 2020-12-08 03:01

    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)})();
    
    0 讨论(0)
提交回复
热议问题