Link to home
Start Free TrialLog in
Avatar of sasnaktiv
sasnaktivFlag for United States of America

asked on

iFrame is killing javascript

Okay Guys,
This is really weird.
I created a page that is meant to prevent the visitor from using the Browser's Back Button.
And it functions very nicely in both FireFox and Safari.

You can see it working properly here: "http://www.stopsnoopers.com/DetectBACK/DetectGoBACK.html"

But once I place the exact same page within an iFrame, it fails to perform at all.
You can see how it's not working here: "http://www.stopsnoopers.com/DetectBACK/DetectGoBACKiFrame.html"

It's the identical page. So why is it failing once placed in an iFrame? And how can it be fixed to function as intended in the iFrame?

Any ideas? Any solutions?
Thanks,
Sas
Avatar of Gary
Gary
Flag of Ireland image

What is die() supposed to be doing - that is a PHP function
Avatar of sasnaktiv

ASKER

I picked up "die()" from a javascript tutorial.
Should I delete the else statement altogether?
Well they probably had a function called die, just remove it.
Hi Gary,
First I removed the die() alone == no change in performance.
Then I removed the entire else statement == no change in performance.

But it still functions properly outside of the iFrame.
What do you think?
Sas
I guess the persistence only applies to the parent page and not the iframe which is a subset of the page and doesn't have it's own cache - I'm not 100% sure.

I'll have a ponder...though I don't see the purpose of something if it doesn't work cross browser.
As a user, I get IFRAME errors (now) only from Mail.com. As such, I stopped using Mail.com with Windows 8 / IE11.

I used to get a lot of IFRAME errors, and assuming (1) all sites cannot be bad and (2) some site corrupted my IE11, I did a full reset of IE11 and also disabled Java add-ins in IE11. Reliability went up enormously and only Mail.com is a problem. It has to be their fault.
Your iframe code is not a valid HTML page.  You are missing the </head> tag and maybe some other things.  That can affect the operation of the page.  You should make it a valid page before you decide whether it works or not.

And there is no reason that javascript (in general) should not work in an iframe.  An iframe is another web page that is displayed inside the iframe.  Doesn't mean that you can't write a javascript function that doesn't work...
Well Dave, it does now, and that has no effect.
And I agree, that's why I placed a conspicuous java Back Button on the page for a test.
Sas
Yeah Dave,
My HTML may not always be proper. Or maybe just dated. And I don't necessarily think the "validator" is correct in some of it's error flags.

But as you say "It may not make a difference".
And it indeed does not have any bearing on the issue at hand. Simply because any errors are constant regardless of whether the page is being presented by itself (where the javascript functions properly) or in an iFrame (where the javascript fails).
It should work either way, right?

Please understand that I appreciate your input.
So, what's causing it to fail in frames???
Sas
I don't know yet.  I didn't see anything yet in the Firefox Error Console that would tell me anything.

But I do know that browsers work better with proper code.  And bad formatting or missing tags can cause them to interpret things 'wrong' meaning not as you want.
Yeah Dave,   My HTML may not always be proper. Or maybe just dated   <-- Yes, and so I as a user with Windows 8 / Windows 10 and IE11 suffer with a barrage of IE and Java "Stopped working".  I know I am not a Java programmer and did not enter the discussion this way. If you are looking for a way to keep me away from your site, you succeeded marvelously well.
Wouldn't it be easier to just check a cookie
On page load check if cookie is set - if not then set the cookie and load the page
If cookie is set then redirect.
Or using the same logic local storage (but that doesn't work in Opera Mini)
Hi Gary,
Setting a cookie as you suggest might indeed be easier, if I knew how to do that.
I don't.
Can you help with that?

Then again, do you think I'd have the same problem when the page is in an iFrame?
Sas
http://www.w3schools.com/js/js_cookies.asp
The iframe would have it's own cookies seperate from the parent so would be no problem.
Only if they are not from the same origin or the path is set to something else than /
If you just set a cookie, the parent window can read it too
You should note that any of these methods if they work, not only prevent the person from going 'back' to that page, they also prevent them from going to that page to order another item.
Thanks for the heads up Dave. I guess I should not waste anymore time trying to learn how to make this work with cookies. Right?

I have found that the javascript I've presented to you in "http://stopsnoopers.com/DetectBACK/DetectGoBACK.html" functions properly and depending on where the Java Alert is targeted the customer can indeed buy more of whatever is for sale. The page functions just fine when it's out of frames.

The problem is once it's in an iFrame (which the page must be eventually) "http://stopsnoopers.com/DetectBACK/DetectGoBACKiFrame.html" it just doesn't present the Java Alert and therefore fails. It's as though the script is not being called on by the addEventListener

So, I'm thinking (maybe wrongly, again) that the problem is with the addEventListener. Is there another way to fire up the script when the BACK button is pressed?

Here's another thought -- When a PHP page (that's what this will be eventually) is reloaded by a pressed BACK Button -- can that reloaded PHP page actually reload new updated data from MySQL, or is it "stuck" with the initial $variables it had the first time it was parsed? Or can it count ($count<'0';) how many times the page was reloaded, then change the initial $variables?

Am I asking too many questions for one day?
I hope there's a "yes" answer to more than this last question.
Thanks Guys,
Sas
What is the point of the iframe?
Navigation control
Using frames for navigation died out in the last century and I'm sure there is a law against it
The better choice is to use AJAX
I don't know AJAX and I can't rewrite a site that consists of hundreds of pages.
So, I'm stuck with the frames (which does not capture any external pages) like it or not.

But what do you guys think about some of the questions I raised?
Sas
Did the use of 'sessions' solve the initial problem where people were getting things for free?
Unfortunately it did not, Dave.
I had rewritten all the pages involved to include 'sessions' with no effect.

I just can't understand why the JavaScript fails when in a frame of any kind.
Sas
Okay Guys,
I think I may have solved it using a totally different approach that's in one of my recent questions.
I need to do some testing and I'll let you know the outcome--maybe tomorrow.
Thanks
Sas
ASKER CERTIFIED SOLUTION
Avatar of sasnaktiv
sasnaktiv
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial