How does Digg remove "& x = 0 & y = 0" from its search results URL?

I use the image as a submit button for the search form, i.e.:

<input id="search" type="image" alt="Search" src="/images/searchButton.png" name=""/>

This has an unfortunate side effect in Chrome and Firefox - the parameters & x = 0 & y = 0 appear at the end of the URL of the search results, for example, if I search for "food", I go to the page:

main/search?search=food&x=0&y=0

Some hunting on the Internet indicated that this is standard behavior when you use an image to submit a form.

I noticed that Digg.com uses the image to submit its search form, but avoids this behavior. I can’t understand how they do it. It seems that they are not using Javascript to submit the form. Can anyone tell?

+3
source share
4 answers

Digg uses JavaScript to do this. Try submitting the search form with JavaScript disabled in your browser.

+4
source

Instead of using, <input type="image">you can use an element <button>:

<button type="submit" style="border: 0; background: transparent">
  <img src="image.png"></img>
</button>
+2
source

, , , , . , JavaScript , , . , , .submit() , .

+1

Javascript , , :

<script>
yourForm.onSubmit = function() {
 location.href = 'main/search?search=' + encodeURIComponent(yourForm.elements['query'].value);
 return false;
}
</script>

, , Javascript.

EDIT: By the way, you can also use a simple form that will submit the form when clicked.

0
source

Source: https://habr.com/ru/post/1726744/


All Articles