在iFrame jQuery中选择一个元素 [英] Selecting an element in iFrame jQuery

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

问题描述

在我们的应用程序中,我们解析一个网页并将其加载到iFrame中的另一个页面中。该加载页面中的所有元素都有其tokenid-s。我需要通过那些tokenid-s选择元素。意思是 - 我点击主页面上的一个元素,然后在iFrame的页面中选择相应的元素。在jQuery的帮助下,我按照以下方式进行:

In our application, we parse a web page and load it into another page in an iFrame. All the elements in that loaded page have their tokenid-s. I need to select the elements by those tokenid-s. Means - I click on an element on the main page and select corresponding element in the page in the iFrame. With the help of jQuery I'm doing it in the following way:

function selectElement(token) {
     $('[tokenid=' + token + ']').addClass('border'); 
}

但是使用此功能我只能选择当前页面中的元素,而不是在iFrame中。有人能告诉我如何在加载的iFrame中选择元素吗?

However with this function I can select the elements in the current page only, not in the iFrame. Could anybody tell me how can I select the elements in the loaded iFrame?

谢谢。

推荐答案

var iframe = $('iframe'); // or some other selector to get the iframe
$('[tokenid=' + token + ']', iframe.contents()).addClass('border');

另请注意,如果 src 这个iframe指向其他域名,由于安全原因,您将无法在javascript中访问此iframe的内容。

Also note that if the src of this iframe is pointing to a different domain, due to security reasons, you will not be able to access the contents of this iframe in javascript.

这篇关于在iFrame jQuery中选择一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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