0

I'm creating a Web Search Engine Here's my code:

<!-- Searching script -->
<script>
  function show() {
    const s = document.getElementById('inputId').value;
    window.location.replace("https://www.google.com/search?q=" + s);
  }

  function clear() {
    <!-- I do not know how to write the code for this part -->
  }
</script>

<input onclick="clear()" type="button">Clear Browsing History</input>
<h1>Search The Web</h1>
<!-- Search Button and input -->
<form id="searchForm" onsubmit="event.preventDefault()">
  <input type="search" name="searchField" id="inputId" placeholder="Search QuickSearch">
  <input type="submit" value="Search" onclick="show()">
</form>

I don't really know how i would even do it

Bumhan Yu
  • 2,078
  • 1
  • 10
  • 20
QuickMash
  • 15
  • 6
  • 2
    Inline event handlers like `onclick` are [bad practice](/q/11737873/4642212). They’re an [obsolete, cumbersome, and unintuitive](/a/43459991/4642212) way to listen for events. Always [use `addEventListener`](//developer.mozilla.org/en/docs/Learn/JavaScript/Building_blocks/Events#inline_event_handlers_%E2%80%94_dont_use_these) instead. `onclick="clear()"` will never work for the reasons outlined in [JS function named `animate` doesn't work in Chrome, but works in IE](/q/28173800/4642212). The global [`event`](//developer.mozilla.org/en/docs/Web/API/Window/event) is deprecated. – Sebastian Simon Dec 19 '22 at 17:23
  • You can add `autocomplete="off"` – Konrad Dec 19 '22 at 17:32
  • @QuickMash How is it relevant that the browser is Chrome-based? Implicit `onclick` scoping works the same in all browsers; `window.event` is universally deprecated. – Sebastian Simon Dec 19 '22 at 17:52
  • [Sebastian Simon](https://stackoverflow.com/users/4642212/sebastian-simon) Its a chrome based browser, but maybe Event would work. Here's the thing, I've only ever used OnClick in my buttons. The button that would do it is on 14 and the scripts "function clear() { } is on line 9. And to [Konrad](https://stackoverflow.com/users/5089567/konrad) I need it to clear from a button.I just want to say **COMMENTS ARE ALSO HARD TO READ**. [Github](https://github.com/QuickMash/search/blob/main/index.html) – QuickMash Dec 19 '22 at 18:01
  • @SebastianSimon how would i implement it? – QuickMash Dec 19 '22 at 18:31
  • Im sorry if any of this is a little crazy – QuickMash Dec 19 '22 at 18:33
  • syntax aside, you can't clear browser history with js – Lawrence Cherone Dec 19 '22 at 20:08
  • Is there any other way, like using other code languages? – QuickMash Dec 19 '22 at 20:26
  • @QuickMash How would other languages help here? JavaScript is the only language that anything remotely related to this problem natively has bindings to. It’s not about the language, it’s about the environment you’re in: in the Web environment, it’s not possible to clear the browser history; but a Web Extension, for example, might allow access, but this is unlikely to be what you want. Read the documentation on the [`autocomplete` attribute](//developer.mozilla.org/en/docs/Web/HTML/Attributes/autocomplete). This is the API that most closely relates to this question. Maybe you’ll find something. – Sebastian Simon Dec 19 '22 at 20:46

1 Answers1

0

Heres the answer. ITS IMPOSSIBLE TO CLEAR HISTORY The only way is to recreate the history using div boxes.

QuickMash
  • 15
  • 6
  • If anyone was wondering about the answer box below, that was because i wanted to see everything without clicking expand. – QuickMash Dec 20 '22 at 02:10