1

javascript code:

<script>

    function searchall()
    {
        var search = document.getElementById("txtSearch");
        var frame1 = document.getElementById("frame1");

        frame1.src = "https://www.google.co.in/search?q=" + search.value;
        alert(frame1.src);
    }

</script>

html code:

<asp:TextBox ID="txtSearch" runat="server" class="form-control my-txt-box" ></asp:TextBox>
    <input id="btnAll" class="my-btn" onclick="searchall()" type="button" value="Search All" />

        <iframe id="frame1" src="home.aspx">
            does not support
        </iframe>

my code seems to be correct but still iFrame does not show the result, its blank. I dont understand why. I even checked with alert(frame1.src); iframe src is setting correct but not showing result.

please help

2
  • Your HTML is missing txtSearch - is it there in your code? Commented Mar 10, 2017 at 18:26
  • yes its there please see the updated code: Commented Mar 10, 2017 at 18:32

2 Answers 2

3

It gives me an error (search.value undefined) where is the txtSearch input ?

If I put a txtSearch input it gives me the folowing error:

Refused to display 'https://www.google.co.in/search?q=xxx' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.

The header of HTTP response from google.com has:

x-frame-options:SAMEORIGIN

It disables the page rendering in an iframe. See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options

http://codepen.io/anon/pen/MppZGX

EDIT: The iframe hosting option for displaying search results is no longer supported by google. See: https://support.google.com/customsearch/answer/4542055?hl=en and https://support.google.com/customsearch/answer/2641279?hl=en

Sign up to request clarification or add additional context in comments.

2 Comments

ok, I got you, so is there any other way to achieve what I want.??
See stackoverflow.com/questions/6666423/… . This could be possible if you add a header in your main page.
0

Try to refresh your iframe on function ending:

var iframe = document.getElementById('youriframe');
iframe.src = iframe.src;

Also, switch var "search" ID by "btnAll". The "txtSearch" is not on your HTML.

1 Comment

@ArnoldParge your variable it's not right: var search = document.getElementById("txtSearch");. There is no input with ID called txtSearch, you put "btnAll". Try to set the same.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.