I want to create a Delicious bookmarklet in Firefox that bookmarks the current page with a predefined tag.
For proof of concept, if I enter this url, it works:
https://john:pwd@api.del.icio.us/v1/posts/add?url=http://www.google.com&
description=http://www.google.com&tags=testtag
But this as a bookmarklet doesn't, I get access denied:
javascript:(
function()
{
location.href = 'https://john:pwd@api.del.icio.us/v1/posts/add?url='
+ encodeURIComponent(window.location.href)
+ '&description=' + encodeURIComponent(document.title)
+ '&tags=testtag';
}
)()
Is this possible via a javascript bookmark?
Update: I tried this, but still got the access denied error, so it has something to do with Javascript/Firefox.
javascript:(
function()
{
location.href = 'https://john:pwd@api.del.icio.us/v1/posts/add?url='
+ 'http://www.google.com'
+ '&description=' + 'http://www.google.com' + '&tags=testtag';
}
)()
Update 2: After trying many variations of the above and on different browsers, I still can't get past the access denied message, so offering a bounty.
I suspect this is Firefox trying to protect you from security issues when running Javascript. When I tried typing in your example into my address bar, Firefox prompted me to ask if I am sure I want to log in to
api.del.icio.us
.This other question concerning HTTP auth looks similar to your question, maybe it will help you.
Update:
I used Firebug's Net panel and its Javascript console, and I was able to see the request/response headers.
Here is the request from the Javascript console, which FAILED:
And, here is the request from the address bar, which WORKED:
The only difference seems to be the
Referer
header, which caused the access denied response. The setting network.http.sendRefererHeader in Firefox's about.config can be set to 0 which turns off theReferer
header. When I tried this, then the Javascript console method started working.There is a Firefox extension called refspoof which is useful for sending your own custom
Referer
headers, maybe that can help here.Looks like you're missing
url=
.