Solved

Javascript to replace and iframe (brake out)

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

867 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

17 Experts available now in Live!

Get 1:1 Help Now