Html google search link

How to add custom google search bar inside your web-page?

A search bar is necessary for a good website. Creating your own search engine from scratch might be a difficult task but this task can be skipped with the help of Google. Google has created a website to create a custom search bar, to create your own check the below link.

https://programmablesearchengine.google.com/about/

Creating a Custom Search Bar: On this website, anyone can easily program their search bar by just selecting the sites you want to be searched for. Follow the steps explained below.

  • Step 1: Go to the following site and hit Get Started button.
  • Step 2: Select the New search engine button to create a new search engine.
  • Step 3: Fill the details as directed on the page and then click the create button.
  • Step 4: After hitting create you will get your code by hitting the Get Code button on the screen shown.

Note: You can modify your setting about searching sites, searching images, safe search from control panel and you can also set to show advertisement while searching through your search bar.

Embedding the Search Bar on a Webpage: After getting your code you can simply paste it inside your web page to see the working search bar.

  • Example: You can see that the output screen has a search bar with an option to search which shows the result from the sites or domain you have selected while creating this search bar. Moreover, this search option will automatically change as you change the sites from the control panel. Currently, the search results are been shown in the default manner. Apart from that, you can manipulate the result displaying manner and much more as directed on the below links
https://developers.google.com/custom-search/docs/element

Источник

Читайте также:  Python pil no module named image

If you know HTML, it’s relatively easy to make links to Google’s search results. Following each link in the examples below is the code that produces it.

See search results in the same browser window

See search results in a new window

Open a new window containing the search results for the query

The URL — that is, the text shown in Italics here: href ) is replaced by %22 .

The easiest way to find the correct encoding is to type your query into a Google Search box. Then run the search and look at the resulting URL in your web browser’s address box (which is usually in the toolbar at the top of the window). Copy and paste the parts you need from the URL into your HTML code.

With AdSense for Search, you can easily create a revenue stream at the same time as provide a Google search box like the following.

Fill the search box with a query by specifying a value the attribute “value”, which AdSense for Search initializes to the null string (”»).

Note: If you fill the search box with a query, Google may not share revenue with you.

AdSense for WebSearch + SiteSearch

AdSense for WebSearch + SiteSearch allows users to search the web or the specific site(s) of your choice.

Note: AdSense for Search centers the search box on the page while AdSense for WebSearch+SiteSearch doesn’t. Of course, you can modify the AdSense code to place the search box wherever you want on the page.

Exercises

These problems are intended to give you practice in creating links to Google’s search results.

  1. On one of your web pages, create a link to a Google search result.
  2. On one of your web pages, create a link that opens a new window and displays a Google search result.
  3. Use AdSense for Search to create a Google search box on a page in your website. You’ll need to sign up for an AdSense account first.
  4. On one of your web pages, using AdSense for WebSearch + SiteSearch, create a Google search box with a radio button for searching your site. Get an AdSense account before doing this problem.

This page was last modified on: Tuesday March 13, 2007

Источник

How can I add a Google search box to my website?

I am trying to add a Google search box to my own website. I would like it to search Google itself, not my site. There was some code I had that use to work, but no longer does:

When I try making a search, it just directs to the Google homepage. Well, actually it directs here: https://www.google.com/webhp Does anyone have a different solution? What am I doing wrong?

5 Answers 5

Sorry for replying on an older question, but I would like to clarify the last question.

You use a «get» method for your form. When the name of your input-field is «g», it will make a URL like this:

https://www.google.com/search?g=[value from input-field] 

But when you search with google, you notice the following URL:

https://www.google.nl/search?q=google+search+bar 

Google uses the «q» Querystring variable as it’s search-query. Therefor, renaming your field from «g» to «q» solved the problem.

This is one of the way to add google site search to websites:

This is awesome! Thank you. I’m making a start page for my local web server, so this will be great once I make it look pretty with CSS. Thanks!

Figured it out, folks! for the NAME of the text box, you have to use «q». I had «g» just for my own personal preferences. But apparently it has to be «q».

(The reason your code isn’t working is because the GET request name is now «q» instead of «g».

I recommend using one of the two methods below:

Method 1: Simply send a GET request directly to Google (Best and most simple option)

Another (more complicated) answer would be

Method 2: Use JS to redirect to Google

First Step. This is the search box. Copy this code where you want in your html/php pages. People will search here the information. This form will send the search results to another html page called search.html

  
Search in website -->

Second Step. Create a new html page named search.html . And add this code in the section, more likely before :

YOUR-NUMBER-CODE you can get from this link https://cse.google.com/cse/all (Here you must add your new search engine.. Also, put OFF on the option «Search the entire web» in order to find results only on your website, not the entire web)

Step Three. Copy this code in the section on the same page: search.html

If you want to search for our articles on a specific topic, write the search term in the form below.

Источник

How to show google.com in an iframe?

I am trying to put google.com into an iframe on my website, this works with many other websites including yahoo. But it does not work with google as it just shows a blank iframe. Why does it not render? Are there any tricks to do that? I have tried it in an usual way to show a website in an iframe like this:

 

Don’t quote me, but maybe google uses something like window.property or something, that, inside an IFrame, would break part of the display?

@PaulAlanTaylor It was my client’s requirement, it was said that he want to show the google result in his website handy in an iframe.

Just do this:

9 Answers 9

The reason for this is, that Google is sending an «X-Frame-Options: SAMEORIGIN» response header. This option prevents the browser from displaying iFrames that are not hosted on the same domain as the parent page.

I think this is pretty useless. If anyone can think of a reason to use that feature apart from just being mean feel free to tell me.

@niutech Incredibly, your URL with the ?igu=1 parameter works. Any idea why? What’s the original purpose behind that option? Interestingly, this causes me to show as not logged in, but the search field still suggests some of my actual historical searches. So I’m «kind of» logged in. Very strange.

IT IS NOT IMPOSSIBLE.
Use a reverse proxy server to handle the Different-Origin-Problem. I used to using Nginx with proxy_pass to change the url of page. you can have a try.

Another way is to write a simple proxy page runs on server by yourself, just request from Google and output the result to the client.

Google blocked my simple attempts at curling their standard search url. 🙁 I ended up using «Google Custom» which sends different X-Frame-Options. google.com/custom?q=test&btnG=Search

As it has been outlined here, because Google is sending an «X-Frame-Options: SAMEORIGIN» response header you cannot simply set the src to «http://www.google.com» in a iframe.

If you want to embed Google into an iframe you can do what sudopeople suggested in a comment above and use a Google custom search link like the following. This worked great for me (left ‘q=’ blank to start with blank search).

 

This answer no longer works. For information, and instructions on how to replace an iframe search with a google custom search element check out: https://support.google.com/customsearch/answer/2641279

Hey Krzysztof Przygoda I think you can force a image search with a src like: http://www.google.com/search?site=imghp&tbm=isch&q=’searchstring’ but because it uses search? and not custom? you will not be able to use it in a iframe

@ScottyG Is the above technique still valid? I tried dropping that line into a blank page and allI get is a blank iframe, even when I provide a query

Hi Andres, looks like you might be right. I am not longer able to get this to work for me. The custom search link now redirects to google.ca/webhp?btnG=&gws_rd=ssl which forces ssl and appears to be blocked in a iframe now. I will keep investigating this but it looks like the party might be over on this one. 🙁

You can use https://www.google.com/search?igu=1 instead of https://google.com/ , it works. This issue is it has X-Frame-Options Header policy and browsers follow those policies.

The content inside the iframe is way bigger than the iframe itself. Any clue how to make the content inside be sized correctly, ie be responsive in relation to the size of iframe it is in? Like you would think if the iframe was small width, then Google would just do a mobile layout that fits the width available.

You can solve using Google CSE (Custom Searche Engine), which can be easily inserted into an iframe. You can create your own search engine, that search selected sites or also in entire Google’s database.

The results can be styled as you prefer, also similar to Google style. Google CSE works with web and images search.

yourpage.php

You can bypass X-Frame-Options in an using YQL.

var iframe = document.getElementsByTagName('iframe')[0]; var url = iframe.src; var getData = function (data) < if (data && data.query && data.query.results && data.query.results.resources && data.query.results.resources.content && data.query.results.resources.status == 200) loadHTML(data.query.results.resources.content); else if (data && data.error && data.error.description) loadHTML(data.error.description); else loadHTML('Error: Cannot load ' + url); >; var loadURL = function (src) < url = src; var script = document.createElement('script'); script.src = 'https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20data.headers%20where%20url%3D%22' + encodeURIComponent(url) + '%22&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=getData'; document.body.appendChild(script); >; var loadHTML = function (html) < iframe.src = 'about:blank'; iframe.contentWindow.document.open(); iframe.contentWindow.document.write(html.replace(//i, 'document.addEventListener("click", function(e) < if(e.target && e.target.nodeName == "A") < e.preventDefault(); parent.loadURL(e.target.href); >>);')); iframe.contentWindow.document.close(); > loadURL(iframe.src); 
 

It is working but not for first time. If I open my webpage in which I have embedded, I have to hit refresh to load page for first time. After that it will be good.

tested also on codepen [codepen.io/anon/pen/Xyqqvb] and it works (although sometime requires to refresh) on firefox,chrome,opera, does not work on edge BUT if I copy locally and I open into browser it continues to reload the page..here the full script: [files.fm/u/arzrb2h4]

If you are using PHP you can use file_get_contents() to print the content:

This will print whatever content file_get_contents() function gets in this url. Please note that since you are displaying content as string instead as a actual web page, things like relative path images are not shown correctly, because /img/myimg.jpg is now loading from your server and not from google.com anymore.

However, you can play with some tricks like str_replace() function to replace absolute urls in images:

)» data-controller=»se-share-sheet» data-se-share-sheet-title=»Share a link to this answer» data-se-share-sheet-subtitle=»» data-se-share-sheet-post-type=»answer» data-se-share-sheet-social=»facebook twitter devto» data-se-share-sheet-location=»2″ data-se-share-sheet-license-url=»https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f4.0%2f» data-se-share-sheet-license-name=»CC BY-SA 4.0″ data-s-popover-placement=»bottom-start»>Share
)» title=»»>Improve this answer
Add a comment |
2

This used to work because I used it to create custom Google searches with my own options. Google made changes on their end and broke my private customized search page 🙁 No longer working sample below. It was very useful for complex search patterns.

I guess the better option is to just use Curl or similar.

Источник

Оцените статью