Question

On my computer, I'm using a custom adblock based on HOSTS redirection (so I can have adblock in Chrome). I'm running IIS on my machine, so I have a custom blank 404 error that displays when an iframe-based ad is displayed on a page.

I've modified my 404 error to inherit its background color from its parent so that the ad doesn't look obnoxious on sites with a non-white background. My next challenge is to use my 404 page to completely collapse the iframe so that it doesn't display on the page at all.

Is it possible to alter the containing <iframe /> tag from within the iframe? I just want to change the height & width attributes if this is possible. If so, how would I go about doing this?

Was it helpful?

Solution

Shouldn't be possible, as sites within iframes can be external site. Allowing them to manipulate the environment they're displayed in would be a browser security risk.

You'd be better off using an adblocking proxy.

OTHER TIPS

If I understand you correctly, you're saying you want your 404 page to trigger a collapse of the iframe when it loads inside it. The easiest way to do this is to create a function in the parent page, and then call it from the 404 when it loads.

For example, if your iframe has the id "advertFrame" you could add the following javascript function to the parent page:

function hideAdvertFrame() {
  var advertFrame = document.getElementById("advertFrame");
  advertFrame.style.height = 0;
  advertFrame.style.width = 0;
}

Then in the 404 page, you can call the function immediately when it loads:

<body onload="window.parent.hideAdvertFrame();">

That said, I think you still might want to consider other options besides cross frame scripting that are less prone to security holes. Maybe your parent page can use AJAX to check if the adblock will have a valid URL before it loads, and then dynamically add it to the page once certain.

The page that fills the iframe cannot alter anything about the page that contains the iframe. If it could, then it would be a huge security risk. To be sure, I tried just what you're asking using the two domains that I'm given at school. Simply put, it didn't work; I got a permission denied error in Firebug.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top