How to add CSS property to elements outside iframe

2019-08-07 09:57发布

问题:

I'm sorry if this wasn't the right place to ask. I'm having trouble figuring this one out.

What I'm trying to do is removing the demo bar provided by marketplaces like themeforest or mojothemes within my own demo site.

But since what appears in the marketplace's live demo of a theme is fetched, it appears within an iframe inside of their site.

I've tried asking in their forums but no one has been helpful.

Is there any way to do about this? An example done in a marketplace would be great.

回答1:

The Answer is No. It is not possible to modify dome elements outside iframe by a script on site in iframe.

Reason: Since The Marketplace website is Accessing your Demo Site within iFrame at thier server. Like how you embed a YouTube Video on your Page and Specify a Heading above it etc, does youtube or google map ever try to change their container styles? do they ever change the heading you wrote above the embed code? Thats it



回答2:

You cannot (due to the Cross Site Scripting - http://en.wikipedia.org/wiki/Cross-site_scripting) as it is a separated document. But what You can do is to use Web Messenging: http://en.wikipedia.org/wiki/Web_Messaging to affect JS/CSS within the iframe (but this will require actions on both sides).