Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7766547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:26:52+00:00 2026-06-01T15:26:52+00:00

Javascript: inFrame = true; try { if(window.top == self) { inFrame = false; }

  • 0

Javascript:

inFrame = true;
try {
   if(window.top == self) {
       inFrame = false;
   }
} catch (err){}

try {
   if(window.parent.location == self.location){
        inFrame = false;    
   }
} catch (err){}

This is a piece of javascript code I use to detect whether my library is inside an iframe.
1 out of 100% of requests report that my library is inside an iframe which I think is not possible.

Is there a possibility that this code to fail [report true on false or vice versa]?

From access log [I log every such iframe requests]

  1. I found that it happens in all modern browsers [ie 6-9, chrome, ff, safari] from user agent string.
  2. I couldn’t make any sense out of referrer because they are same as my publisher site.
  3. In some cases I found for same referrer, same url requested & same client ip my library had been once inside an iframe & not in other. This made me doubt the above code.

Will there be any difference while window or document is being loaded in the properties [self, location, top, parent] I use to check? Because my script loads and executes synchronously mostly before the document is ready or window is completely loaded and that does the iniframe test to proceed further.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:26:53+00:00Added an answer on June 1, 2026 at 3:26 pm

    You know most modern browsers allow you to “View Frame” right? As in, view the frame content without the parent. That’s an entirely plausable answer for 3. (I do it all the time).

    A plausible cause of 1 and 2 is that self is not really defined in javascript therefore may not always be equal to window. You should therefore be checking window or better yet window.self not self like Özgür suggests.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is some code on the javascript side for form-based uploads: iframe.setAttribute('src', 'javascript:false;'); I'm
i have the following piece of code in the page HEAD: <script type=text/javascript> $(document).ready(function(){
i use javascript to judge a page is in a iframe: if (this !=
I have created a webView: videoView.delegate = self; videoView.userInteractionEnabled = true; [videoView loadRequest:[[NSURLRequest alloc]initWithURL:[[NSURL
I have a javascript tooltip that I'd like to call a jquery modal window
js undefined error we have the following widget code : index.html <script type=text/javascript language=javascript>
I am working on one project and I am using JavaScript code to get
Possible Duplicate: Cross-browser window resize event - JavaScript / jQuery Jquery flash of unstyled
I'm submitting a form using a call to this JavaScript function: function emailFriend(){ jQuery(form[name='comparisons']).attr(action,
Tried to make a little old school ajax (iframe-javascript) script. A bit of mootools

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.