View Full Version : Popup message in iframe

11-23-2011, 08:45 PM
For the people that have iframe another website before: Have you iframe a website but when you try to leave the page a box would popup and says some thing like are you sure you want to leave the page, is there a way I can stop that?

11-23-2011, 08:51 PM
Short, no there is no way to do this using an iframe from an external source. You don't control that code, you just give it a window to see it.
Long answer, yes you can. But it requires you to fetch the source from the third party site and replace javascript. This can be performed using a library such as curl.

All and all, as soon as you refer to HTML elements, this is not a PHP issue. And blocking the JS is also not a PHP issue. The only thing that PHP may do here is fetch all the code remotely and display it locally, but that means getting rid of the iframe completely since that now becomes useless to use.

11-25-2011, 03:23 PM
Have this code here:

(function() {
var proxied = window.alert;
window.alert = function() {
// do something here
return proxied.apply(this, arguments);

Would I be able to still do it with the code above, how could I use it for html?

11-25-2011, 05:02 PM
I have no idea what you are asking. That is Javascript, not PHP. All I am saying is if you use an iframe you don't have control over the source of the requested link. You may be able to use javascript to block another javascript, but that would be a question to ask the client developers.

11-29-2011, 01:39 AM
I'm trying to stop that "are you sure you want to leave" box from popping up all the time.

11-29-2011, 02:36 AM
I'm trying to stop that "are you sure you want to leave" box from popping up all the time.

I know what you want to do. And I'll say it again, if you use an iframe with an external source, its not your source code. You can see if there's a way in javascript to prevent such a popup, but from PHP world all you can do is read the source code from the remote and display it as your own. I recommend avoiding such a thing as often as you can as its easy to tag as a phishing site if you do so.