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 9235595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:05:17+00:00 2026-06-18T07:05:17+00:00

exampleA.com <iframe src=http://exampleB.com/> exampleB.com <button onclick=top.location=’/test’>Test</button> In Chrome (and I assume most browsers), clicking

  • 0

exampleA.com

<iframe src="http://exampleB.com/">

exampleB.com

<button onclick="top.location='/test'">Test</button>

In Chrome (and I assume most browsers), clicking on the “Test” button inside the iframe changes the parent page to exampleB.com/test, but in IE it sets the location relative to the parent URL (exampleA.com/test).

How can I make the test button work in all browsers with a URL relative to the iframe?


NOTE:

This can be done in HTML like: <a href="/test" target="top">Test</a> as mentioned in the comments. See this question.

However, I need(ed) a JavaScript-based solution for the parent location to be changed in reaction to an event, rather than a mouse click.

  • 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-18T07:05:19+00:00Added an answer on June 18, 2026 at 7:05 am

    Looks like I’ve answered my own question…

    exampleB.com

    <button onclick="topLocation('/test')">Test</button>
    
    <script>
    var topLocation = function(url) {
        // make sure its a relative url
        if (url[0] === '/' && url[1] !== '/'){
            // x-broswer window.location.origin 
            if (!window.location.origin) window.location.origin = window.location.protocol+"//"+window.location.host;
            window.top.location = window.location.origin + url;
        } else {
            window.top.location = url;
        }
    }
    </script>
    

    I found the code to get the base url (window.location.origin) from this SO answer

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

Sidebar

Related Questions

For example: <iframe name=Stack src=http://stackoverflow.com/ width=740 frameborder=0 scrolling=no id=iframe> ... </iframe> I want it
Is there any difference between the following code blocks? <iframe src="http://example.com" width=100%></iframe> <iframe src=http://example.com
I have a parent window with the URL: http://example.com?val=test In the iframe of that
I have an URL in IFRAME with parameters like this: <iframe src=http://www.example.com/id=123&place=123></iframe> Works perfectly
If I open a dialog like so: $('<iframe id=externalSite class=externalSite src=http://www.example.com />').dialog({ autoOpen: true,
<iframe align=middle src=http://www.example.com?id=5555555 width=100% height=300> </iframe> How can I pass this id value to
example: at this domain http://www.example.com/234234/go.html is only one iframe-code how can i get the
CSS iframe { display: none; } JS $('iframe').load(function() { $('iframe').fadeIn('slow'); }); HTML <a href=http://example.com
Suppose we have the following HTML file: <html xmlns=http://www.w3.org/1999/xhtml> <head> <title>Test iframe download</title> <script
Suppose I have a page located at www.example.com/foo , and it contains an <iframe>

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.