我可以从内部更改iFrame的源吗? [英] Can I change an iFrame's source from within?

查看:142
本文介绍了我可以从内部更改iFrame的源吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个问题,我有麻烦的措辞清楚;仔细读。我想知道是否可以改变iFrame的源代码(通过iFrame显示的页面)来改变它的内部源代码,而不改变iFrame的父页面的源代码。



例如:



如果我在我的网页中创建iFrame,并单击iFrame中的传统链接,位置)的主页(我创建了iF的页面)将被更改,而不是iFrame的内容。



我想改为通过框架内容改变iFrame的来源(这个可以是跨域内容)到框架本身内的新位置。


我注意到JS方法中改变页面的
位置。 这个SO问题有一些详细的。
改变页面的某些方法行为不同,我注意到,例如不允许
用户使用返回按钮到达用户
导航的页面。


使用这些不同的JS位置更改方法之一,我认为这是可能的,但我不知道如何做。 p>

问题:



如果iFrame请求的网页正在与其协作,是否有可能实现iFrame资源更改其自身位置的结果?

解决方案

对于iframe中的任何锚标记,请尝试将目标设置为_self。像这样:

 < a href =/ mynewlinkwithiniframe.htmltarget =_ self> Test< / a> 

我会玩的,但我知道这是老学校的标准。 / p>

EDIT
根据我做的一些测试,iframe中锚链接的默认操作是在iframe中加载新内容。 target =_ self是多余的,除非有其他原因覆盖它。也许你应该提供更多关于源代码的信息,如果这不是为你解决。



我也可以假设你正在使用javascript 。如果您正在使用window.location.href,您需要更改为:



而不是:

  window.location.href ='newpage.html'; 

尝试:

 code> window.open('/ newpage.html','_self'); 


This is a question that I'm having trouble wording clearly; read carefully. I want to know whether or not it's possible for the source of an iFrame (the page displayed via the iFrame) to change it's inner source without changing the source of the iFrame's parent page.

For example:

If I create an iFrame in my web page, and click a traditional link within the iFrame, the source (location) of the master page (the page where I've created the iF) will be changed rather than the iFrame's content.


I want, instead, to change the source of the iFrame via the framed content (this could be cross-domain content) to a new location within the frame itself.

I've noticed different behaviors in JS methods of changing a page's location. This SO question has a few of them detailed. Some methods of changing the page behave differently, I noticed, such as not allowing the user to use the back button to get to the page that the user navigated from.

Using one of these different JS location changing methods, I thought this could be possible, but I'm not sure how it would be done.

The question:

Provided that the iFrame's requested web page is cooperating with it, is it possible to achieve the result of an iFrame resource changing its own location? If so, how is it done?

解决方案

For any anchor tags within the iframe, try setting the target to _self. Like this:

<a href="/mynewlinkwithiniframe.html" target="_self">Test</a>

I'll play around with it, but I know this was the standard for old school frames.

EDIT Based on some tests I did, the default action for anchor links within an iframe is to load the new content within the iframe. target="_self" is redundant unless there is something else overriding it. Maybe you should supply more info about the source code if this isn't resolving it for you.

I could also make an assumption that you are running into the problem using javascript. If you are using window.location.href, you'll want to change that as follows:

Instead Of:

window.location.href = 'newpage.html';

Try:

window.open('/newpage.html', '_self');

这篇关于我可以从内部更改iFrame的源吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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