JSFiddle - React, Tailwind, and code Playground
by AltayH
HTML
<script async src="https://cse.google.com/cse.js?cx=000888210889775888983:3gepro1fol8"></script>
<div class="gcse-searchresults-only"></div>
JavaScript
let key = "q";
let value = "test";
key = encodeURI(key); value = encodeURI(value);
var kvp = document.location.search.substr(1).split('&');
var i=kvp.length; var x; while(i--)
{
x = kvp[i].split('=');
if (x[0]==key)
{
x[1] = value;
kvp[i] = x.join('=');
break;
}
}
if(i<0) {kvp[kvp.length] = [key,value].join('=');}
//this will reload the page, it's likely better to store this until finished
document.location.search = kvp.join('&');