-1

Here's an example i m trying to run to delete a div element with class "location_description" in iframe but it doesnt work. Any solution?

HTML

<div id="kk">
    <iframe id = "weatherFrame" src="https://www.meteoblue.com/el/%CE%BA%CE%B1%CE%B9%CF%81%CF%8C%CF%82/widget/daily?geoloc=detect&days=4&tempunit=CELSIUS&windunit=KILOMETER_PER_HOUR&coloured=coloured&pictoicon=1&maxtemperature=1&mintemperature=1&layout=light"  frameborder="0" scrolling="NO" allowtransparency="true" sandbox="allow-same-origin allow-scripts allow-popups" class = "weatherFrame" style = "width: 60%;height: 100%;"></iframe>
    <div> 
        <a href="https://www.meteoblue.com/el/%CE%BA%CE%B1%CE%B9%CF%81%CF%8C%CF%82/%CF%80%CF%81%CF%8C%CE%B3%CE%BD%CF%89%CF%83%CE%B7/%CE%B5%CE%B2%CE%B4%CE%BF%CE%BC%CE%AC%CE%B4%CE%B1?utm_source=weather_widget&utm_medium=linkus&utm_content=daily&utm_campaign=Weather%2BWidget" target="_blank"></a>
    </div>      
</div>

jQuery (end of <body>)

$('#weatherFrame').load(function(){
    alert("in");
    $("location_description").remove();
});
2
  • 2
    Is the iframe content and the main page on the same domain? Commented Dec 6, 2016 at 16:50
  • where islocation_description ? Commented Dec 6, 2016 at 16:52

2 Answers 2

3

If the domain of the iframe is not the same as the domain of the parent page, you will not be able to manipulate its content due to the same origin policy

If they're different domains but you have control over its content (that is, you can add code to it), you can use Postmessaging to do what you are trying to do. Simply add a listener within the iframe's content which tells it when to fire off this change.

From looking at the domain however I imagine this is not your page so there isn't much you can do

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

Comments

0

Using jquery if you want to remove something by it's class then this will be your statement to do that :

$(".location_description").remove();

And in an iframe, you cannot do such manipulation. You can so some thing as below

     iframe.contentWindow.postMessage('Hello ');

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.