0

I am making a program that hides your history by what you are searching

function bruh() {
  var win = window.open();
  win.document.body.style.margin = '0';
  win.document.body.style.height = '100vh';
  var f = win.document.createElement("iframe");
  window.focus();
  var url = "URLINPUT";
  if (!url) return;
  f.style.width = "100%";
  f.style.height = "100%";
  f.style.border = 'none';
  f.style.margin = '0';
  win.document.body.appendChild(f);
  f.src = url
}

so they input a url. and the URLINPUT changes to what they are trying to search

Barmar
  • 741,623
  • 53
  • 500
  • 612
Kohen Webb
  • 23
  • 3
  • 1
    What's your question? – Lionel Rowe Jun 30 '22 at 23:47
  • I can not figure out how to have it so when they input a website using , it will change the code to the javascript, so that instead of it saying URLINPUT, it will say (for example: youtube.com) if they were to input youtube.com – Kohen Webb Jun 30 '22 at 23:50
  • Does this answer your question? [Set a default parameter value for a JavaScript function](https://stackoverflow.com/questions/894860/set-a-default-parameter-value-for-a-javascript-function) – ethry Jun 30 '22 at 23:57

2 Answers2

0

Make url a function parameter.

function bruh(url) {
  if (!url) return;
  var win = window.open();
  win.document.body.style.margin = '0';
  win.document.body.style.height = '100vh';
  var f = win.document.createElement("iframe");
  f.style.width = "100%";
  f.style.height = "100%";
  f.style.border = 'none';
  f.style.margin = '0';
  win.document.body.appendChild(f);
  f.src = url
}

Then your search field can be something like:

<input id="search" onchange="bruh(this.value)">
Barmar
  • 741,623
  • 53
  • 500
  • 612
0

You can use parameters in your function.

function bruh(url) {
  var win = window.open();
  win.document.body.style.margin = '0';
  win.document.body.style.height = '100vh';
  var f = win.document.createElement("iframe");
  window.focus();
  // url is already declared in function
  if (!url) return;
  f.style.width = "100%";
  f.style.height = "100%";
  f.style.border = 'none';
  f.style.margin = '0';
  win.document.body.appendChild(f);
  f.src = url
}
<html>
  <body>
    <form>
      <input type="text" id="text" placeholder="Please type a URL!" onchange="bruh(this.value);" value="Please type a URL!">
    </form>
  </body>
</html>

This will execute the function when the input is changed with the value of the text input.

More information is on MDN

ethry
  • 731
  • 6
  • 17