Solved

Google search boxes can no longer be altered.

Posted on 2016-10-20
7
23 Views
Last Modified: 2016-10-20
UNFORTUNATELY Google has change the game plan on everyone.  In order to put a google search box on a website it used to go into a <form> tag.  You could then use CSS to alter the look of it.  NOT ANYMORE.  Now you get a generated js script that automatically puts in a search box that looks terrible.  You put these tags " <gcse:search></gcse:search> " where you what the box to appear in your code.  Since the code is generated by google it cannot be altered.  Simply replacing the cx in the old form tag will not work.  Google does not want people to use the form tags anymore, and tried as I did I could not get the form tag format to work with google's new js code.

The only way I can think of to over ride the terrible look of the google box is do so in CSS.  HOWEVER...big problem.  I looked all over the web and cannot find an example or list of the code/css that is being generated between the google <gcse:search></gcse:search> " tags.  Without knowing the code or class generated in the behind code there is no way to change it to something that looks nice.  Google only offers result display choices.  They do not offer box choices.

Do you know of any code examples of what is being generated, or where I could get a list of the CSS class or code that I can use to make the box look decent?

Here is the old style form tag that google does not use anymore:
<form id="local_form" action="http://www.google.com/cse"> <!-- the form action will be changed using javascript -->
				<div class="textfield-container">
					<!-- <label for="search_local_textfield" accesskey="s" class="hidden">Search this site: </label> -->
					<input type="text" name="q" id="search_local_textfield" class="search-textfield" size="35" autocomplete="off" value="Search" onfocus="if(this.value=='Search')this.value=''" onblur="if(this.value=='')this.value='Search'" />
					<input type="hidden" name="cx" value="017201984285415750805:ypbrseilgxg" /> <!-- Update this value with your search engine unique ID. Submit a request to the OTech Service Desk if you don't already know your unique search engine ID. -->
					<input type="hidden" name="cof" value="" /> <!-- this value will be set using javascript -->
					<input type="hidden" name="ie" value="UTF-8" />
					<input type="hidden" name="nojs" value="1" />
				</div>
				<div class="submit-container">
					<button type="submit"></button>
				</div>
			</form>

Open in new window


Here is the new style of code generated by google that can't be altered:
<script>
  (function() {
    var cx = '007869872437826671579:4lzit-stmto';
    var gcse = document.createElement('script');
    gcse.type = 'text/javascript';
    gcse.async = true;
    gcse.src = 'https://cse.google.com/cse.js?cx=' + cx;
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(gcse, s);
  })();
</script>
<gcse:search></gcse:search> 

Open in new window

0
Comment
Question by:smitty62
  • 4
  • 2
7 Comments
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 41852446
Most of these kinds of things are done with iframes that are generated by the javascript.  It give Google and others more control over what is done.  And they can change it whenever they want or need to.
0
 

Author Comment

by:smitty62
ID: 41852453
How do I get around this problem so that I can design my own?  Do you know of any published code examples in using an iframe to customize my own box?
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 41852471
I don't think you can get around it.  All of the code in the iframe is loaded from Google.  It will replace whatever you do.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 20

Accepted Solution

by:
Russ Suter earned 500 total points
ID: 41852474
Looks like it's still possible to edit things but you'll probably need to use the !important keyword to make the CSS stick.

I just did a quick jsfiddle to prove that it works:

https://jsfiddle.net/rsuter/u19nrw77/

Of course this relies on Google not changing its class names randomly.
0
 

Author Comment

by:smitty62
ID: 41852567
Do you know of any complete listings for google class names?
0
 

Author Comment

by:smitty62
ID: 41852590
I was able to select the box in Chrome, right click and choose inspect.  That allowed me to view the code and get the information needed.  Thanks for you help.
0
 

Author Closing Comment

by:smitty62
ID: 41852591
Thank you.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

When writing CSS, there are a few simple rules that will make your life easier.    1. Using ‘* {box-sizing:border-box;}’. Using this will wrap all your elements in a nice little compact box-model that will give you the width you want, like so... …
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now