Solved

iFrame is killing javascript

Posted on 2014-10-11
28
8 Views
Last Modified: 2016-05-09
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
0
Comment
Question by:sasnaktiv
  • 11
  • 7
  • 5
  • +2
28 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40375006
What is die() supposed to be doing - that is a PHP function
0
 
LVL 1

Author Comment

by:sasnaktiv
ID: 40375014
I picked up "die()" from a javascript tutorial.
Should I delete the else statement altogether?
0
 
LVL 58

Expert Comment

by:Gary
ID: 40375016
Well they probably had a function called die, just remove it.
0
 
LVL 1

Author Comment

by:sasnaktiv
ID: 40375019
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
0
 
LVL 58

Expert Comment

by:Gary
ID: 40375042
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.
0
 
LVL 90

Expert Comment

by:John Hurst
ID: 40375102
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.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 40375172
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...
0
 
LVL 1

Author Comment

by:sasnaktiv
ID: 40375186
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
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 40375197
0
 
LVL 1

Author Comment

by:sasnaktiv
ID: 40375208
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
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 40375213
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.
0
 
LVL 90

Expert Comment

by:John Hurst
ID: 40375288
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.
0
 
LVL 58

Expert Comment

by:Gary
ID: 40375314
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)
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 1

Author Comment

by:sasnaktiv
ID: 40375629
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
0
 
LVL 58

Expert Comment

by:Gary
ID: 40375679
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.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 40375772
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
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 40375890
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.
0
 
LVL 1

Author Comment

by:sasnaktiv
ID: 40375943
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
0
 
LVL 58

Expert Comment

by:Gary
ID: 40375951
What is the point of the iframe?
0
 
LVL 1

Author Comment

by:sasnaktiv
ID: 40375956
Navigation control
0
 
LVL 58

Expert Comment

by:Gary
ID: 40375961
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
0
 
LVL 1

Author Comment

by:sasnaktiv
ID: 40375963
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
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 40375982
Did the use of 'sessions' solve the initial problem where people were getting things for free?
0
 
LVL 1

Author Comment

by:sasnaktiv
ID: 40375998
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
0
 
LVL 1

Author Comment

by:sasnaktiv
ID: 40376121
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
0
 
LVL 1

Accepted Solution

by:
sasnaktiv earned 0 total points
ID: 40380773
As promised the solution was the answer to one of my previous questions.
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?

The answer is: Yes!
When a PHP page is reloaded via the Browser's Back Button it can indeed reload new data from MySQL. It is not "stuck" with the values from the initial parse as I thought it would be.

So, when the customer reaches the page that follows the transaction & delivery of goods, simply UPDATE the customer's record in your DB column (e.g.: 'PAID') with a value indicating that fact (e.g.: 'yes'). Then on any previous page that the customer might GO BACK TO place the following code:
$queryPAID = "SELECT PAID FROM YourTable WHERE CustomerUniqueIdentifier ='$CustomerUniqueIdentifier' "; 
$resultPAID = mysql_query($queryPAID) or die(mysql_error());
while($row = mysql_fetch_array($resultPAID)){
$PAID = $row['PAID'];} //$SessionPAID='yes';
if($PAID=='yes'){
echo '<script type="text/javascript">window.alert("THIS eMAIL SESSION HAS BEEN TERMINATED!\n\nREASON: You can not use the Browser\'s Back Button.\nPlease Log-In again.")
location.href = "LogIn.php ";</script>';
   exit;
} 

Open in new window


It works beautifully!
But I still don't know why the original version of Javascript fails within frames and this approach doesn't.

Thanks for the help everyone,
Sas
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now