3

Google came out with a new logo a couple minutes ago and its very very laggy on my computer. I want to keep using the current google style but without the logo. The current id of the logo element is 'hplogo'. So I made a web page that contains google in a iframe and I want to remove that element using jquery.

<head>
        <script src="jquery.js" type="text/javascript"></script>
        <script type="text/javascript">
        $(document).ready(function(){
            $("#google").height($(window).height());

            setTimeout(function(){
                $("#google").contents().find("#hplogo").remove());
            }, 3000);
        });
        </script>

</head>
<body style="margin:0px;">
<iframe id="google" style="border:none;width:100%;overflow:auto;" src="http://www.google.com/">
</iframe>
</body>
</html>

I believe that its not working because its not the same domain. Is there a way around this?

Drake
  • 3,851
  • 8
  • 39
  • 48
  • As per jQuery documentation : "The .contents() method can also be used to get the content document of an iframe, if the iframe is on the same domain as the main page." – Michel Hébert Jul 22 '11 at 06:08
  • 1
    This was answered in another post. Check http://stackoverflow.com/questions/364952/jquery-javascript-accessing-contents-of-an-iframe – Michel Hébert Jul 22 '11 at 06:34
  • `` or just [click here](http://www.google.com/custom?q=&btnG=Search). – davidcondrey Dec 03 '14 at 06:25
  • Does this answer your question? [How can I access the contents of an iframe with JavaScript/jQuery?](https://stackoverflow.com/questions/364952/how-can-i-access-the-contents-of-an-iframe-with-javascript-jquery) – chakeda Aug 24 '23 at 16:07

4 Answers4

0

You really can't. Don't use iframes unless you absolutely have to. If you want to pull some remote content into your website you should consider using ajax, then you can modify the DOM as much as you want.

Dustin Poissant
  • 3,201
  • 1
  • 20
  • 32
0

Usually when you perform such an operation, you use something like -

$('iframe').contents().find('#yourElement')

But, considering the security issues, functions like .contents() .maps() are restricted when the iframe loads a third party domain. In this case, Google is not your local domain, and hence what you are trying to accomplish cannot be achieved. Hope this helps!

Swanidhi
  • 2,029
  • 1
  • 20
  • 21
0

You can't do this with an iframe because of security issues. But you can do with a chrome extension or something else that provides less restrictions. Using a chrome extension, you can inject any script you want inside google.com pages to remove the logo.

gafi
  • 12,113
  • 2
  • 30
  • 32
0

As Micheal stated the answer to your question is no. I had the same problem when i wanted to "invite all friends" with a script and facebook had started using iframes. Look at this question Check all checkboxes inside an iframe (when inviting guests to a facebook event). I solved my problem using greasemonkey which has far less restriction than standard browse, so you can try to check it

Community
  • 1
  • 1
Nicola Peluchetti
  • 76,206
  • 31
  • 145
  • 192