Solved

Javascript to replace and iframe (brake out)

Posted on 2009-07-13
2
375 Views
Last Modified: 2012-05-07
I have a API call that gets returned into an iframe however I want the page to automatically brake out of the iframe i.e. load new page not inside the iframe but to replace the page with a new one.


0
Comment
Question by:pigmentarts
2 Comments
 
LVL 8

Accepted Solution

by:
Bobaran98 earned 500 total points
ID: 24846024
Here's some JavaScript you can include in the body of any page so that, if the page is opened in any frame that doesn't happen to be the top-most frame, it will break out and replace the top level with itself:

<body>
 
  <!-- html code here, etc. etc. //-->
 
  <script language="javascript1.2">
     var mypage = "index.html"; //replace this with the name of your page
     if(window != top) { top.location.replace(mypage); }
  </script>
 
  <!-- html code here, etc. etc. //-->
 
</body>

Open in new window

0
 
LVL 12

Author Comment

by:pigmentarts
ID: 24847966
perfect!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

821 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