---
title: "用js改变框架网页的location有2种方法"
author: "thousandzhang"
date: "2009-12-16T09:55:08Z"
tags: []
categories: ["Web前端"]
slug: "js-location-2"
draft: false
lastmod: "2009-12-16T09:55:08Z"
id: 549427
url: "https://thousandzhang.iteye.com/blog/549427"
---

js框架网页,改变框架的location有2种方法:

方法一：

```
top.mainFrame.location.href = url;
```

方法二：

```
var doc = parent.document;
doc.getElementsByTagName("frame")["mainFrame"].src=url;
```

比较： 当框架网页mainFrame调用了其他系统的纯flash页面,然后再通过菜单子框架页面的js调用其他页面以显示在mainFrame里面时候,会出现js语法报错,用第二种方法就能解决。