Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8800617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:38:11+00:00 2026-06-14T00:38:11+00:00

I want build a custom Google search. I tried this one My Code <div>

  • 0

I want build a custom Google search.

I tried this one

My Code

<div>
<form id="cse-search-box" action="http://google.com/cse" target='if2'>
  <input type="hidden" name="cx" value="009827885688477640989:igzwimalyta" />
  <input type="hidden" name="ie" value="UTF-8" />
  <input type="text" name="q" size="31" />
  <input type="button" name="sa" value="Search" onclick="doit()" />
</form>
</div>
<div>
<iframe name="if2" id="if2" width="100%" height="600px" marginheight="0" frameborder="0">
</iframe>
</div>

its working.
Then I try to remove the height scroll bar when more data is coming from Google.
but it is saying error like
Unsafe JavaScript attempt to access frame with URL google.com/… from frame with URL 192.168.9.185/KLMS/CustomGoogleSearch.aspx. Domains, protocols and ports must match

so is there any method to fetch the data from Google without using Iframe (like ajax call)
[EDIT]

I tried

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link rel="stylesheet" type="text/css" href="CSS/Search.css" />
    <script type="text/javascript" src="JS/jquery-1.4.2.min.js"></script>
    <script type="text/javascript" src="JS/CustomSearch.js"></script>
</head>
<body>
<div>
    <form id="cse-search-box" action="http://google.com/cse" target='if2'>
        <input type="hidden" name="cx" value="009827885688477640989:igzwimalyta" />
        <input type="hidden" name="ie" value="UTF-8" />
        <input type="text" name="q" size="31" />
        <input type="button" name="sa" value="Search" onclick="doit()" />
    </form>
</div>
<div>
    <form id="frmSearch" runat="server" autocomplete="off">
        <div id="mainSearchContainer">
            <!-- Container to show Internal search result -->
            <div class="searchResult">
                <!-- Show Item search result (Currently Tip) -->
                <div class="itemResult">
                    <fieldset>
                        <legend>Items</legend>

                        <div class="resultContainer">
                        </div>
                    </fieldset>
                </div>

                <!-- Show People search result (currently PointCat members) -->
                <div class="peopleResult">
                    <fieldset>
                        <legend>People</legend>

                        <div class="resultContainer">
                        </div>
                    </fieldset>
                </div>
            </div>
        </div>
    </form>
</div>

<div>
    <iframe name="if2" id="if2" width="100%" height="600px" marginheight="0" frameborder="0"></iframe>
</div>
<script type="text/javascript">
    // get AJAX http request
    var xmlhttp = getXMLHttpRequest();
    function getXMLHttpRequest() {
        var xhr;
        if (window.XMLHttpRequest) {
            //code for IE7+, Firefox, Chrome, Opera, Safari
            xhr = new XMLHttpRequest();
        }
        else {
            //code for IE6, IE5
            xhr = ActiveXObject("Microsoft.XMLHTTP");
        }
        return xhr;
    }
    window.doit = function () {
        xmlhttp.onreadystatechange = function () {
            document.forms["cse-search-box"].submit();
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                //This is used when AJAX returns
                //xmlhttp.responseText contains all markup sent back from google

                //Determine size of iframe
                $("#if2").attr('width', '100%');
                $("#if2").attr('height', textHeight(xmlhttp.responseText) + "px");

                //Used to set the contents of the iframe
                //May have to be adapted to get the response to a specific place in the iframe tag hierarchy
                $("#if2").attr('src', "data:text/html;charset=UTF-8," + escape(xmlhttp.responseText));
            }
        };
        xmlhttp.open("POST", "http://google.com/cse", true);
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlhttp.send("cx=009827885688477640989:igzwimalyta&ie=UTF-8&q=31");

    };
    //Measures the size of the returned text
    function textHeight(text) {
        $("body").append('<span id="tempSpan" style="display:block;">' + text + '</span>');
        var height = $("#tempSpan").height();
        $("#tempSpan").remove();
        return height;
    };
</script>
</body>
</html>

[/edit]

Please help.

thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T00:38:12+00:00Added an answer on June 14, 2026 at 12:38 am

    What you could try is to use an ajax call, and when it returns set the size of the iframe.

    // get AJAX http request
    var xmlhttp = getXMLHttpRequest();
    function getXMLHttpRequest() {
    var xhr;
    if (window.XMLHttpRequest) {
        //code for IE7+, Firefox, Chrome, Opera, Safari
        xhr = new XMLHttpRequest();
    }
    else {
        //code for IE6, IE5
        xhr = ActiveXObject("Microsoft.XMLHTTP");
    }
    return xhr;
    }
    

    Send AJAX request and listen for response:

    window.doit = function() {
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                //This is used when AJAX returns
                //xmlhttp.responseText contains all markup sent back from google
    
                //Determine size of iframe
                $("#if2").attr('width', '100%');
                $("#if2").attr('height', textHeight(xmlhttp.responseText) + "px");
    
                //Used to set the contents of the iframe
                //May have to be adapted to get the response to a specific place in the iframe tag hierarchy
                $("#if2").attr('src', "data:text/html;charset=UTF-8," + escape(xmlhttp.responseText));
            }
        };
        xmlhttp.open("POST", "http://google.com/cse", true);
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlhttp.send("cx=009827885688477640989:igzwimalyta&ie=UTF-8&q=31");
    };
    

    Measure the height of the response (adapted from Calculating text width):

    //Measures the size of the returned text
    function textHeight(text){
      $("body").append('<span id="tempSpan" style="display:block;">' + text + '</span>');
      var height = $("#tempSpan").height();
      $("#tempSpan").remove();
      return height;
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to google custom search and I want to include that in my
i want to build a custom event with jQuery that is not set to
I want to build an app that works like custom URL app where I
I create an Android project for build my custom widget, and I want to
I want build a sketch pad app on iPhone, I assume that this type
I'm using Google Engine App with Python. I want to add custom user authentication.
I want to build a custom control to reuse in my project which consists
I want to build a custom document management web application that ties in with
What I want to do is use google analytic's custom event tracking from within
I want to build custom controls in ASP.NET MVC 3. I want to create

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.