使用javascript更改iframe中的网址 [英] Change URL in an iframe using javascript

查看:70
本文介绍了使用javascript更改iframe中的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iframe,它从父页面调用一个函数。该函数是window.location,但这不会更改url。有没有办法让iframe从父页面调用一个函数,这将导致iframe更改网址?我也有一个基本的qustion,如果我有一个iframe,并点击一个链接,让我进入一个新页面,父页面是否保持打开状态?

I have a in an iframe, that calls a function from the parent page. The function is window.location, however this does not change the url. Is there a way to have the iframe call a function from the parent page, that will cause the iframe to change url? I also had a basic qustion, if I have an iframe, and click on a link that brings me to a new page, does the parent page remain open?

谢谢你提前帮助。对不起,如果我听起来像个完全白痴,我是javascript的新手。

Thanks in advance for your help. Sorry if I sound like a complete idiot, I am new to javascript.

戴夫

推荐答案

window.location 不是函数,它是对象

要做你想做的事,首先让iframe从父母那里调用一个特殊的函数。

To do what you want, first make the iframe call a special function from it's parent.

parent.sendMeToGoogle();

在函数中(在父级中)执行以下操作:

And in the function (in parent) do something like:

function sendMeToGoogle(){
    document.getElementById('iframeID').src="http://google.com/";
}

这篇关于使用javascript更改iframe中的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆