0

I'm simply trying to load another webpage in my webpage using the object tag or iframe. Then, I would like to remove some element of the loaded page with jQuery.

Here is my code

<div> 
    <object type="text/html" data="http://ebird.org/ebird/map/eurtre1" width="100%" height="400px" id="eurtre1">
    </object>
 </div>

<script>
jQuery( window ).load(function() {
    jQuery('#map-sidebar').remove();
});
</script>

And, as you guess, it is not working... I have tried:

jQuery('#eurtre1').contents().find('#map-sidebar')

and

jQuery('#eurtre1')[0].contentDocument.children

The wired thing is that on my browser, I can do it in the console, once I've selected the inside of the object...

Any idea ?

1 Answer 1

1

Here's a link to a similar question:

how to access an iframe and affect it with jQuery

Basically you can't due to Javascript same-origin policy but if you have access to the loaded content in the iframe you could use window.postMessage

You could also add a parameter to the iframe's src tag to post a message, something like this:

<iframe src="http://www.example.com?hideElement=true"></iframe>

Again you will have to have access the content of the iframe to check the param and execute your code.

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

Comments

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.