Domparser无法在iFrame中运行 [英] Domparser is not working in iFrame

查看:101
本文介绍了Domparser无法在iFrame中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个文本框和一个按钮。当我在文本框中输入所有特殊字符并单击按钮时,它应该返回我在文本框中输入的相同文本。为此我使用DOMParser函数,它在IE中工作正常,但在Iframme中没有。我的应用程序在Iframe中打开,需要解决此问题。



请帮忙。



谢谢。



我尝试了什么:



不确定如何在iFrames中解决这个问题

作为DOMParser不适用于iFrame。下面是我的代码,它在IE中正常工作,但在iFrame中没有。

Hi,

I have one textbox and a button. When I am entering all the special characters in textbox and clicked on button it should return me the same text which I entered in textbox. For this I am using DOMParser function which is working fine in IE but not in Iframme. My application opens in Iframe and need to fix this problem.

Kindly help.

Thanks.

What I have tried:

Not sure how to fox this issue in iFrames
as DOMParser is not for iFrame. Below is my code which is working fine in IE but not in iFrame.

Function parseText(string){
Var parser = new DOMParser;
Var dom = parser.parseFromString(
'<!doctype.html><body>'+ string,'text/html');
return dom.body.textcontext;
}

推荐答案

您需要记住,当您打开< iframe>时在您的页面上,对于大多数用途,它与常规页面位于不同的位置。因此,根据您调用DOM访问功能的位置,您需要记住它只会查看它自己的页面 - 也就是说,它是自己的范围。



例如,您可以在其内部打开页面的副本。然后它将在父页面和子页面中具有相同的id =''值。 DOM可以区分它们,因为它们处于不同的范围。



注意在'parent'和'child'的前一段中的使用。有能力在一个范围内,并使用对父母或孩子的引用访问另一个范围。



所以 - 取决于您请求数据的位置相对于它的位置是的,你会看到不同的结果(如失败)。考虑一下 - 你可以解决你的问题。
You need to keep in mind that when you open an <iframe> on your page it is, for most purposes, a separate location from your regular page. Thus, depending upon where you call your DOM accessing functionality, you need to keep in mind that it will only look at it's own page - that is, it's own scope.

As an example, you may open a copy of a page inside of itself. It would then have the same id='' values in both the parent and child pages. The DOM can tell them apart because they are in "different scopes".

Note the use in the previous paragraph of 'parent' and 'child'. There is the ability to be in one scope and access the other using references to the parent or child.

So - depending upon where you request the data relative to where it is, you will see different results (like failure). Consider this - you may solve your problem.


这篇关于Domparser无法在iFrame中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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