I'm trying to force my Google Custom Search results to use HTTPS format instead of HTTP. I've dug through the API documentation, and have been unsuccessful in finding out how to make this change. I remember that the old GCSE let you specify HTTP or HTTPS, but it doesn't look like you can anymore since Google updated it.
I've tried going through http://www.google.com/cse/cse.js and changing all of the HTTP occurrences to HTTPS, as well as www.google.com/jsapi and switching between both V1 and V2 methods, but I haven't been successful.
I've dug through and changed every occurrence of HTTP to HTTPS, whether it was relevant or not, and I'm still stuck with all of my search results linking to an HTTP address instead of the desired HTTPS address.
EDIT: CODE
I'm open to using V1 or V2, it doesn't matter.
Here is the V1 code:
<div id='cse' style='width: 100%;'>Loading</div>
<script src='//www.google.com/jsapi' type='text/javascript'></script>
<script type='text/javascript'>
google.load('search', '1', {language: 'en', style: google.loader.themes.DEFAULT});
google.setOnLoadCallback(function() {
var customSearchOptions = {};
customSearchOptions['overlayResults'] = true;
customSearchOptions['adoptions'] = {'layout' : 'noTop'};
var customSearchControl = new google.search.CustomSearchControl('MySearchID', customSearchOptions);
customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
var options = new google.search.DrawOptions();
options.setAutoComplete(true);
customSearchControl.draw('cse', options);
}, true);
Here is the V2 code:
<script>
(function() {
var cx = 'MySearchID';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'https:') +
'//www.google.com/cse/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
})();
</script>
<gcse:search></gcse:search>
I've tried altering the Javascript mentioned at the top, and replacing the Javascript source in V1 and V2 sections to use my JS instead of Google's, but that hasn't fixed the problem for me either. I'm probably overlooking something..
Any ideas?
Thanks!
EDIT #2
Good news, I was able to figure it out.
In using V1 code, you can add this code:
google.search.Csedr.addOverride("mysite_");
Right above the line containing this code:
customSearchControl.draw('cse', options);
To overwrite the existing Google CSS. After doing that, I wrote my own CSS, which follows:
<div class="gs-title">
<a class="gs-title" data-attr="{href:unescapedUrl.replace('http://','https://'),target:target}" data-body="html(title.replace('mySiteTitle :: ', ''))"></a>
</div>
Results still show HTTP, but the tooltip reads HTTPS, and leads to the proper HTTPS page.
I can't answer my own question due to having less than 10 reputation right away, but I'll mark it answered in a few hours when the feature becomes available to me.