---
title: "跳出iframe返回外层页面"
author: "g21121"
date: "2012-02-15T16:36:21Z"
tags: []
categories: ["企业架构"]
slug: "iframe"
draft: false
lastmod: "2012-02-15T16:36:21Z"
id: 1407377
url: "https://286.iteye.com/blog/1407377"
---

在web开发过程中难免要用到iframe，但当连接超时或跳转到公共页面时就会出现超时页面显示在iframe中，这时我们就需要跳出这个iframe到达一个公共页面去。

首先跳转到一个中间页，这个页面用于判断是否在iframe中，在页面加载的过程中调用如下代码：

```
<script type="text/javascript">
//<!--
function isIFrameSelf(){try{if(window.top ==window){return false;}else{return true;}}catch(e){return true;}}
function toHome(){ if(!isIFrameSelf()){ window.location.href="http://g21121.iteye.com";}}
//-->
</script>
```

 

这样就可以跳转到外层页面了