5

We all know that bookmarklets are nothing but some executable javascript code that do some things for us when we click on them depending on the function that they are intended to do... My Question is:

For example, I have a Bookmarklet, don't know, something like this one:

javascript:void(window.open('http://www.pdfdownload.org/web2pdf/Default.aspx?left=0&right=0&top=0&bottom=0&page=0&cURL='+document.location.href));

As far as I understand, the bookmarklet code (with the "&cURL=" thing) takes the URL that is in the adress bar of the browser and then do something with it in order to get a result. Something similar can be done with a selection, by changing some parameters in the bookmarklet (Like with the "Search selection in Google Maps" one) and some others.

How can I "decompile" a bookmarklet in order to make it take the desired data (in this case an URL) from a form?

For example, let's say I want to use the above bookmarklet in a webpage to provide a form that let's the user input a URL and then click a button to get the result.

I've seen other bookmarklets that get the URL from a "?input=" and others from a "?url="

How can I pass bookmarklet's functions to a form?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Jmlevick
  • 51
  • 2

3 Answers3

1

In a bookmarklet it's actually easiest to use prompt('Please enter a URL', 'default value') instead of the variable. Displaying a form in the current webpage is rather cumbersome.

If you just need one user-entered value, prompt() is an easy to use alternative to ask a user for more info. (Of course you can use multiple prompt() calls, too, but this will probably lead to a confused user)

akirk
  • 6,757
  • 2
  • 34
  • 57
  • @BalusC: Thanks for your quick answer, so, how do I apply "prompt" to the bookmarklet above? And if the bookmarklet uses "?input=" or "?url=" How do prompt will work? how do I manage to integrate it to those bookmarklets? – Jmlevick Jan 21 '11 at 23:41
  • I suppose you mean me. Well, `javascript:void(window.open('http://www.pdfdownload.org/web2pdf/Default.aspx?left=0&right=0&top=0&bottom=0&page=0&cURL='+prompt('Enter a URL')));` – akirk Jan 21 '11 at 23:42
  • @akirk: Yep, sorry for the mistake... Hummm... I tried what you put above, but it doesn't do anything. As far as I understood, if I execute the code you put above, the browser has to ask me for the URL with something like a Javascript alert no? So, what's wrong? – Jmlevick Jan 21 '11 at 23:48
  • if I copy and paste this to my location bar and press enter I get a prompt. so, try again? – akirk Jan 21 '11 at 23:50
  • 1
    Yeah! it works!! (feeling a little "abusive" here, one more thing, well, two: is it possible to do "the form thing" that I mentioned above? What would be the workaround? And, if for example, I want to put this in a webpage I just have to add a link to the bookmarklet's function right? How do I manage to "hide" the bookmarklet to the people that review the source code? How can I protect my source code? Finally, it doesn't matter if the Bookmarklet uses "?Curl=" "?input=" or "?url=" I can always get prompt to work by adding: "+prompt('Enter a URL')));" Right? – Jmlevick Jan 21 '11 at 23:54
0

Try something like this:

<form method="get" action="http://www.pdfdownload.org/web2pdf/Default.aspx">
<input type="hidden" name="left" value="0">
<input type="hidden" name="right" value="0">
<input type="hidden" name="top" value="0">
<input type="hidden" name="bottom" value="0">
<input type="hidden" name="page" value="0">
<input type="text" name="cURL">
<input type="submit">
</form>
Karl Bielefeldt
  • 47,314
  • 10
  • 60
  • 94
0

Maybe you can call a javascript file in your bookmarklet :

javascript:void((function(){var%20e=document.createElement('script');e.setAttribute('type','text/javascript');e.setAttribute('src','http://www.example.com/js.js');document.body.appendChild(e)})())

And you create an iframe on js.js

var site = location.href;
document.body.innerHTML += "<div style='background-color:white;z-index:1000;position:fixed;right:0;top:0' width='300' height='250'><iframe src='http://www.example.com/bookmarklet.php?q=" + site + "' /></div>";
Eray
  • 7,038
  • 16
  • 70
  • 120