Home > Software engineering >  Writing to a field On a web Page
Writing to a field On a web Page

Time:01-26

I want to create a simple HTML that on load will go to a URL and then put text in a textbox on the page. Below is the HTML that I came up with so far. It will open the page but will not enter the text that I put in. Any ideas will be appreciated. Thank you

<!DOCTYPE html>
<html>
<head>


</head>

<body>

<script>
document.body.innerHTML  = '<a href="https://Bing.com/" style="display: none;" id="link">Link</a>';
document.getElementById("link").click();
</script>


<script>
function displayResult(element)
{
document.getElementById(element).value = "TEST";
}

}
</script>

displayResult("sb_form_q");

</body>

</html>

I tried the above code and I wanted it to put the text "TEST" in the text box on the form.

CodePudding user response:

JavaScript (in a <script> element) runs in the current page. Navigating to a new page will kill the currently running JavaScript program.

If you want to run some JavaScript on the subsequent page then you need to put the JavaScript in that page. You, clearly, don't control Bing, so you can't do that.

It would be a major security problem if you could do that.


The nearest you could come to this would be to write a browser extension that had permission to access bing.com.

CodePudding user response:

If you are specifically looking for Bing searches, you will have to introduce parameters into your href="https://Bing.com/" example: https://Bing.com/search?q=SEARCHTHIS

  • Related