I am trying to load a 3rd party website inside an iframe. However, the website has a "frame buster" script that causes it to break out of the iframe and take over the entire page resulting in the user leaving my site.
I found that using the following script will ask the user to confirm whether or not they want to leave my site.
If they select "Cancel" then the user stays on my site and the website will load itself in the iframe as it was intended. However, if the user says OK, then the breakout is successful and they are taken away from my site.
Is there any way to add a function that has the same effect of the "cancel" button on the onbeforeunload box?
If you press cancel everything works as it is intended so I am hoping someone might have a solution to this problem. Any ideas would be greatly appreciated.
Is it possible to alter this script so that it alerts the person prior to going to the specified page?
The desired outcome would be if the user selects "OK" it will take them to "http://www.mywebsite.com/index.php" and if they click "Cancel" they will just remain on the current page.
I tried the following but whenever I try and add return to the code it prompts once then goes to the iframe "breakout" page then prompts again and then goes to the specified URL. I only want one prompt and to have it go directly to the custom URL.
Any ideas on how to get this to work?
Code:
<script language="javascript" type="text/javascript">
var prevent_bust = 0
window.onbeforeunload = function() { prevent_bust++; return "Do you want to leave?";}
setInterval(function() {
if (prevent_bust > 0) {
prevent_bust -= 2
window.top.location = 'http://www.mywebsite.com/index.php'
}
}, 1)
</script>
It ... sends the user to a specified page instead.
this isn't happening to me. can you describe how to recreate this event?
when i click "stay on page" it stay at "/demo/". if i leave, i go to the break page and ultimately, the next page.
at no point to i find a way to "go to the specified page"??
1. If you reply to my post, and your reply would then appear directly beneath my post, DON'T QUOTE MY ENTIRE POST!!! IT'S REDUNTANT!!! IT'S ASININE!!!! IT'S REDUNDANTLY ASININE!!!!! DON'T DO IT!!!!
2. jQuery extends the functionality of JavaScript. If you don't know JavaScript, give up on that jQuery script and learn JavaScript. You'll save yourself a lot of frustration, I promise.
3. Use the [code][/code] tags. Otherwise, you may be left wondering why no one responded to your eyesore of a thread.
this isn't happening to me. can you describe how to recreate this event?
when i click "stay on page" it stay at "/demo/". if i leave, i go to the break page and ultimately, the next page.
at no point to i find a way to "go to the specified page"??
Let me try and clarify.
My goal is to prompt the user when the iframe attempts to break-out. If the user clicks "Cancel" then they remain at the /demo/ directory (the ideal scenario).
If the user clicks "OK" I want to be able to send them directly to a custom URL (and not to the breakout page).
Currently, if you goto the demo you get a prompt. If you click "OK" it takes you to the black "breakout page" where you get prompted again. If you click "OK" again then you finally get taken to the custom URL.
I only want there to be one prompt which takes the user directly to the custom URL so that they are never taken to the breakout page. I can't figure out how to prevent the user from being sent to the breakout page prior to being sent to the custom URL.
before i give you an answer, what browser are you testing in?
1. If you reply to my post, and your reply would then appear directly beneath my post, DON'T QUOTE MY ENTIRE POST!!! IT'S REDUNTANT!!! IT'S ASININE!!!! IT'S REDUNDANTLY ASININE!!!!! DON'T DO IT!!!!
2. jQuery extends the functionality of JavaScript. If you don't know JavaScript, give up on that jQuery script and learn JavaScript. You'll save yourself a lot of frustration, I promise.
3. Use the [code][/code] tags. Otherwise, you may be left wondering why no one responded to your eyesore of a thread.
try your page in internet explorer. are you able to get to "mywebsite.com"?
1. If you reply to my post, and your reply would then appear directly beneath my post, DON'T QUOTE MY ENTIRE POST!!! IT'S REDUNTANT!!! IT'S ASININE!!!! IT'S REDUNDANTLY ASININE!!!!! DON'T DO IT!!!!
2. jQuery extends the functionality of JavaScript. If you don't know JavaScript, give up on that jQuery script and learn JavaScript. You'll save yourself a lot of frustration, I promise.
3. Use the [code][/code] tags. Otherwise, you may be left wondering why no one responded to your eyesore of a thread.
1. you set a "control variable"
2. you set tell the window what to do if it gets unloaded.
3. then you tell setInterval to happen. the "if" inside of setInterval is not yet evaluated because the you've only just declared the set interval. even if the time was set to 0, the anonymous function would not yet be evaluated.
4. the rest of the HTML is written to the DOM.
5. setInterval starts being called over and over and over and over
6. in the meantime, eventually the "breakout page" is loaded. by design, it tries to redirect the webpage
7. this triggers onbeforeunload
8. for right now, setInterval is halted. it is no longer being called over and over and over because the onbeforeunload has to be evaluated
9. while evaluating your onbeforeunload, your "control variable" is increased by one.
10. after the increase, your "return" causes the first "stay" or "leave" prompt.
11. the script is waiting for a response from the user. the script will not continue until a response from the "stay" or "leave" prompt is received
so naturally, the person has to make a choice. either:
A) they click "stay". if so:
A1. execution of the script continues. the "prevent_bust" IF statement is evaluated
A2. since your control variable has been increased, your IF statement will evaluate to TRUE
A3. because of this, your control variable will be decreased
A4. now that we're in the if statement, your script tells the browser to change the url to "mywebsite.com".
A5. this fires onbeforeunload again because of the "mywebsite.com" redirection.
A6. the person then gets ANOTHER prompt to "stay" or "leave". this is your second prompt. "stay" leaves them on the "demo" page with "setInterval" running over and over and over forever, evaluating at FALSE every time because you set the control variable to "-1". clicking "leave" would send them to "mywebsite.com"
B) they click "leave". if so:
B1. the user is redirected to the "breakout page"
B2. your scripts from the "demo" page may finish, and if you injected any further prompts, they might temporarily fire, but...
B3. as soon as the "breakout page" is loaded, bye bye. it takes precedent and control. there's nothing else you can do.
here's the code that got me this far:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>
</head>
<body>
<script language="javascript" type="text/javascript">
var index = 0
var prevent_bust = 0
window.onbeforeunload = function() { prevent_bust++; return "frame is trying to redirect. okay to allow redirection to breakout page.";}
setInterval(function() {
if (prevent_bust > 0) {
prevent_bust -= 2
if(confirm("because of the frame break and the way this code is designed to catch the frame break attempt, you HAVE TO ANSWER THIS QUESTION!!!!!\n\n\n click okay to get redirected to mywebsite.com\n\nclick cancel to finish script and stay on the current page"))
{
window.onbeforeunload = function() {}
window.top.location = 'http://www.mywebsite.com/index.php'
}
else
alert("nothing else will now happen except that setInterval will run over and over and over. this if statement will never be touched again because prevent_bust =" + prevent_bust)
}
}, 1)
</script>
<iframe src="http://www.24sevenphotography.com/demo/break.html" style="border:0px #FFFFFF none;" name="myiFrame" scrolling="no" frameborder="0" marginheight="0px" marginwidth="0px" height="1px" width="1px"></iframe>
</body>
</html>
Last edited by Angry Black Man; 03-04-2012 at 06:39 PM.
1. If you reply to my post, and your reply would then appear directly beneath my post, DON'T QUOTE MY ENTIRE POST!!! IT'S REDUNTANT!!! IT'S ASININE!!!! IT'S REDUNDANTLY ASININE!!!!! DON'T DO IT!!!!
2. jQuery extends the functionality of JavaScript. If you don't know JavaScript, give up on that jQuery script and learn JavaScript. You'll save yourself a lot of frustration, I promise.
3. Use the [code][/code] tags. Otherwise, you may be left wondering why no one responded to your eyesore of a thread.
the code i provided eliminates one of the prompts if the user chooses to stay on the website, and they get a prompt to either go to the mywebsite.com site or to stay put.
1. If you reply to my post, and your reply would then appear directly beneath my post, DON'T QUOTE MY ENTIRE POST!!! IT'S REDUNTANT!!! IT'S ASININE!!!! IT'S REDUNDANTLY ASININE!!!!! DON'T DO IT!!!!
2. jQuery extends the functionality of JavaScript. If you don't know JavaScript, give up on that jQuery script and learn JavaScript. You'll save yourself a lot of frustration, I promise.
3. Use the [code][/code] tags. Otherwise, you may be left wondering why no one responded to your eyesore of a thread.
I did some testing with your code and here's what I found.
Firefox.) Nothing changes, still get 2 prompts, only the message in the prompt is different
Chrome.) The user never gets to "mywebsite.com" as they get stuck on the "breakout page"
IE.) I still get 2 prompts but eventually end up at "mywebsite.com"
The script below works exactly how I want it to when there is not prompt. When I add a prompt everything goes haywire.
I just simply want to add a single prompt before the person gets sent directly to "mywebsite.com" and if they choose to stay then they get no additional prompts and just remain where they are.
Bookmarks