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

  • Home
  • SEARCH
  • 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 6996593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:10:39+00:00 2026-05-27T20:10:39+00:00

I have a page with one button. When clicked, that button navigates to http://google.com/

  • 0

I have a page with one button. When clicked, that button navigates to http://google.com/

$("#button").click(function(){
  window.location="http://google.com";
});

I would like this navigation to work when this page is embedded within the iframe. I don’t want to affect the outside host page, but rather only the contents of the iframe. What’s a good cross-platform way to:

  1. Detect if I’m contained in an iframe
  2. If not, navigate like above.
  3. If yes, navigate the iframe only?

(I’m going to try to implement the algorithm I just described, but regardless I think this question is interesting enough to be posted. If I succeed, I’ll post my solution)

  • 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-05-27T20:10:40+00:00Added an answer on May 27, 2026 at 8:10 pm

    1) Detect if I’m contained in an iframe

    if (window != window.top) { 
        // the page is inside an iframe
    }
    

    2) If not, navigate like above.

    navigate like above

    3) If yes, navigate the iframe only?

    When you write window.location.href = 'http://www.google.com'; you are navigating the contents of the iframe, not that of the top page. If you want to navigate the top page, you can only do this if this top page is on the same domain as the iframe and you could use window.top.location.href.


    UPDATE:

    There is a security mechanism built in browsers which forbid you from redirecting to sites that set the X-Frame-Options: SAMEORIGIN response header when inside an iframe. That’s the case with http://www.google.com. Simply navigate to this site and look at the response HTTP headers with FireBug or developer toolbar you are using and you will see this header. You cannot redirect to it and you will get the following error message:

    Refused to display document because display forbidden by X-Frame-Options.
    

    It’s basically a security mechanism implemented by some sites whose authors didn’t want you to embed them in an iframe.

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

Sidebar

Related Questions

Need some help from javascript gurus. I have one page where http://www.google.com/finance/converter is embedded
I have a page (parent) that when a button (with .click funciton) is clicked
I have google analytics on my site. One page has a button which when
I have a page with two buttons, one Button opens a popup window with
I have 6 text boxes on an asp page and one search button. Users
I have an aspx page with multiple FileUpload controls and one Upload button. In
How to insert an event to the aspx.cs page. I have one asp:button and
I have a page in one of my client's websites that generates an extensive
It has been stated that the google plus-one button works it's way up the
I've got a web page with a button that opens another window. When the

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.