简体   繁体   English

Greasemonkey iframe内容访问jQuery

[英]Greasemonkey iframe content access jQuery

I had the wrong impression that using Greasemonkey would allow me unrestricted access to iframe's elements as jQuery selectors.. 我有一个错误的印象,即使用Greasemonkey将允许我不受限制地访问jQuery选择器来访问iframe的元素。

The HTML page example: HTML页面示例:

     <html>
         <body>
              <div id='content'>

                     //Here is the first iframe

                 <iframe src='bla.php'>

                       <html>
                       <body>
                       <div id='content2'>

                          //Here another iframe is inserted
                          <iframe src='bla2.php'>
                                //Here some simple elements

                                   <div id="goal">
                                          My password is Secret
                                  </div>

                          </iframe>


                       </div>
                     </body>
                    <html>
                 </iframe>

              </div>
         </body>
     <html>

So I'm trying to find if the #goal selector contains Secret, and tried using 所以我试图查找#goal选择器是否包含Secret,并尝试使用

     $('#goal').text().search('Secret');

Obviously it doesn't work, tried getting the whole DOM as a variable and used the variable.indexOf('Secret') .. but after debugging, the DOM content does not contain the iframes contents. 显然,它不起作用,尝试将整个DOM作为变量使用,并使用了variable.indexOf('Secret')..但在调试后,DOM内容不包含iframe内容。

Any solution I may use ? 我可以使用任何解决方案吗? Some Greasemonkey settings I may apply ?. 我可以应用某些Greasemonkey设置吗? Thank you. 谢谢。

iframe的处理方式有所不同,jQuery具有第二个可选参数,与使用的文档DOM相关,默认为document,并将其设置为iframe文档即可。

   $('#goal', frames[0][0].document ).text().search('Secret');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM