Solved

Javascript to replace and iframe (brake out)

Posted on 2009-07-13
2
372 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

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

Join & Write a Comment

This article discusses how to create an extensible mechanism for linked drop downs.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

708 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