Feb 9, 2020

Why is my Google CSE search icon in the header for chrome on mobile not working?

This is very strange and a bit frustrating. Here is the issue. When using Google Chrome for mobile, I head to our website, touch the search icon in the header and a highlight animation happens but the search box will not populate. After that failed attempt, a hashtag is now at the end of the URL. It does not matter what page I am on, the URL will add a hashtag at the end. The menu icon in the header will do the same thing. I then have to refresh the page in order to get the search box to work. I even deleted the hashtag, pressed enter, and the search box populated that way as well as refreshing the page. I cannot replicate the issue via Mozilla Firefox or Webroot Secure Anywhere Browsers for mobile. Another interesting thing is that the issue happened on Desktop via Google Chrome Incognito. Now, once you get the search to populate like normal (after a refresh) and search for something it will populate the results. However, when on the results page, if you click on the search icon in the header, it clears the search results, adds a hashtag to the end of the URL, and no longer works again for mobile via chrome and desktop via chrome incognito. It works fine in Firefox for desktop and mobile; it doesn't matter if I am in Incognito or not.

Unfortunately, I could not find anything related to my topic over the internet. I am a beginner and have tried to figure it out but I have no clue where to start or where to look.

I want to mention that I use WordPress and set up Google CSE with the Layout set to Compact using their Default Theme and have added CSS to style the search box and results. I have run several tests and only one result prevailed. Also, one thing I want to note in doing all of my tests is I cleared my cache via browser and Supercacher for my website. The first test was to deactivate all plugins and that did not change anything. The second step was to delete the CSS I added and that did nothing. Then, I changed the theme and that worked. Our theme, BuddyBoss, has a search.php file and a searchform.php file. The theme I switched to only has a searchform.php file (not sure if that matters at all). I deleted the PHP in the searchform.php file and added the following code (using my Child Theme):

(function() { var cx = 'CSE ID'; var gcse = document.createElement('script'); gcse.type = 'text/javascript'; gcse.async = true; gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//cse.google.com/cse.js?cx=' + cx; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gcse, s); })(); </script> <gcse:searchbox-only resultsUrl="https://www.example.com/"></gcse:searchbox-only>

If any of you need a copy of the CSS I implemented, just let me know.

Is there some type of code I can put in to fix this issue or is it something else? I understand that this may be a little more complex, so I appreciate the time you give me as well as any help I get. Hopefully, it will be an easy thing to fix. If not, any direction anyone can give me would be greatly appreciated!

I hope I was clear, easy to follow, and answered all of your questions. Thank you!

Thanks and regards,

Josh
Locked
Informational notification.
This question is locked and replying has been disabled.
Community content may not be verified or up-to-date. Learn more.
Last edited Feb 9, 2020
Recommended Answer
Feb 11, 2020
Hi,

Yes, the code which you have mentioned is the old code.

Please review the documents below to understand CSE implementation with new code and examples:

Thanks
Original Poster Tug_T4G marked this as an answer
Helpful?
All Replies (5)
Feb 10, 2020
Hi,

1. Can you please provide examples/screenshots to illustrate your query.
2. Please provide with the website URL where you are seeing the problem when accessing on mobile/Chrome browser.
3. Please provide your CSE Search Engine ID.

Thanks
Feb 10, 2020
Hi Deepak,

Thank you for getting back to me!
  1. Here is the screenshot:   I have also attached the link to the screenshot http://prntscr.com/qzze5p.
  2. https://www.tips4gamers.com/
  3. Here is the CSE ID: 011375891578627155239:6fwzp18lklq
Thank you for taking the time to investigate this. You are much appreciated!

Thanks and regards,

Josh
Feb 10, 2020
Hi,

Thanks for the information provided.

Looked into your website source code and observed that you have implemented your CSE engine using the deprecated code. You will need to implement your CSE engine with the new code provided on the CSE control panel for the same layout which you have selected.

Please access your CSE control panel and grab the lasted code and implement on your website and then check of you are seeing the problem which you have reported.

Please review the document below for details of new Element code:

Thanks
Feb 11, 2020
Hi Deepak,

Thank you for that information. I changed where I placed the codes beside one, which I believe that the code I provided: 

(function() { var cx = 'CSE ID'; var gcse = document.createElement('script'); gcse.type = 'text/javascript'; gcse.async = true; gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//cse.google.com/cse.js?cx=' + cx; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gcse, s); })(); </script> <gcse:searchbox-only resultsUrl="https://www.example.com/"></gcse:searchbox-only>

is the code that is outdated, correct? That code is in my searchform.php file. I have been trying to figure out what to put in my searchform.php file to completely change over our theme's search to Google's search. Google's search is so much better than anything else out there and I am a beginner at coding so your help is much appreciated.

Moreover, I am not sure if you can point me in the right direction on trying to figure out what to put in the PHP file or not? If not, that is completely fine I understand. All articles I came across has been seriously outdated. That is actually where I got the above code.

Thanks and regards,

Josh
Recommended Answer
Feb 11, 2020
Hi,

Yes, the code which you have mentioned is the old code.

Please review the documents below to understand CSE implementation with new code and examples:

Thanks
Original Poster Tug_T4G marked this as an answer
false
12280057106139628021
true
Search Help Center
true
true
true
true
true
0
false
false
Search
Clear search
Close search
Main menu