开发者

JQuery access iframe elements

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>
</b开发者_运维知识库ody>
</html>

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


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


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.


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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜