11

How do you make a new search engine in Google Chrome if the search term has to be a POST variable?

I tried translating the POST data into a GET querystring with the %s placeholder but this didn't work.

1
  • Why don't you use google search api instead ?
    – Piotr Kula
    Jan 23, 2012 at 22:00

3 Answers 3

18

Try javascript: URL

I managed to get what I want with this (pretty nasty indeed) workaround: a javascript: URL that creates and immediately submits the form. This means, when you define your search engine, instead of a URL like this:

http://www.example.com/search?term=%s

you would use this URL/code:

javascript:document.write('<form name="f" action="http://www.example.com/search" method="POST"><input type="hidden" name="term" value="%s"></form><script>f.submit();</script>');

Since it'll most likely be a pretty long string it's better to prepare it in a text editor and then copy-paste it into the URL bar.

Example: This is the search URL for an Italian-English dictionary:

javascript:document.write('<form name="f" action="http://dizionari.repubblica.it/cgi-bin/inglese/find" method="POST"><input type="hidden" name="lemma" value="%s"><input type="hidden" name="sez" value="ita"></form><script>f.submit();</script>');

And here the same thing again, but with the single line manually reformatted into multiple lines to make it easier to read and understand:

document.write(
    '
        <form
            name="f"
            action="http://dizionari.repubblica.it/cgi-bin/inglese/find"
            method="POST"
        >
            <input
                type="hidden" 
                name="lemma" 
                value="%s"
            >
            <input
                type="hidden"
                name="sez"
                value="ita"
            >
        </form>
        <script>
            f.submit();
        </script>
    '
);

P.S. Unfortunately, this method doesn't work when performing search from empty "New Tab" page. This can be fixed by installing "Ultimate New tab" extension.

2
2

I have converted @etuardu's solution into this one, not using document.write(), if that's what you prefer:

javascript:f=document.createElement('form');f.method='post';f.action='http://www.example.com/search';i=document.createElement('input');i.name='term';i.value='%s';f.appendChild(i);document.body.appendChild(f);f.submit();

1

First you need to host page with this PHP code:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
    <form name="f" action=""<?php echo htmlspecialchars($_GET['action']); ?>" method="POST">
        <input type="hidden" name="<?php echo htmlspecialchars($_GET['inputname']); ?>" value=""<?php echo htmlspecialchars($_GET['inputvalue']); ?>">
    </form>
    <script>f.submit();</script>
</body>
</html>

Then put in search url:

http://yourwebsite.com/filename.php?action=http://sitetosearch.com/search.php&inputname=query&inputvalue=%s

(replace urls, filenames and input name to your data)

For example (search on http://fansubs.ru/search.php via host http://webercom.ru/):

http://webercom.ru/post.php?action=http://fansubs.ru/search.php&inputname=query&inputvalue=%

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .