I am trying to make a bookmarklet for my website.
I have made a php page that when sent a GET for example www.website.com/index.html?a=banana it will return echo 'stand';
Now I am trying to make a bookmarklet that when I press it will:
Do the GET to the php page, then display whatever the echo was back to the user in a small popup that disapears after 3 seconds.
How can I do this?
Instapaper bookmarklet does it…
javascript:
function%20iprl5(){
var%20d=document,z=d.createElement('scr'+'ipt'),b=d.body,l=d.location;
try{
if(!b)
throw(0);
d.title='(Saving...)%20'+d.title;
z.setAttribute('src',l.protocol+'//www.instapaper.com/j/deyNbbpjuSei?u='+encodeURIComponent(l.href)+'&t='+(new%20Date().getTime()));
b.appendChild(z);
}
catch(e){
alert('Please%20wait%20until%20the%20page%20has%20loaded.');
}
}
iprl5();
void(0)
A bookmarklet is a piece of javascript that runs in the scope of the page you are on.
It is not meant to just call arbitrary urls and cannot do so since that would be in violation of same origin practice. If your PHP can return JSONP, then you can write a bookmarklet that will insert a script on the page that envokes the script you return – that would be able to display a popup too
paste this
view-source:http://www.instapaper.com/j/deyNbbpjuSei?u=http://www.stackoverflow.cominto the location bar to see the amount of stuff returned as part of the page you are on