亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何選擇位于頁面上 iframe 中的 html 元素

如何選擇位于頁面上 iframe 中的 html 元素

Helenr 2021-08-20 19:30:36
我正在編寫 webextension 以簡化帳戶管理員登錄帳戶,當我嘗試使用 js 獲取登錄輸入時嘗試自動將用戶登錄到 angularjs 應用程序中,但未找到。該元素在瀏覽器的檢查器面板中表示,但在頁面源中不存在。UPD:我找到了問題的原因——這個元素位于頁面上的 iframe 中,我當前的問題是如何訪問 iframe 的文檔。我發現在 devtools 控制臺中有命令 'cd' 正是我所需要的:var ifr = document.getElementById('aid-auth-widget-iFrame');var ifrContent = ifr.contentWindow;cd(ifrContent);document.getElementById('sign-in').value = 'login';但是 'cd' 不能從頁面上的腳本中執行。接下來我確實嘗試訪問框架的文檔:var ifr = document.getElementById('aid-auth-widget-iFrame');ifr.contentWindow.document;SecurityError: Permission denied to access property "document" on cross-origin object是否可以在頁面上現有的 iframe 中執行 js 或選擇和操作此 iframe 中的元素?棄用的問題內容: 我發現 angular.element 可能會有所幫助,但它也找不到元素??赡苁且驗槲覈L試了“文檔”,我使用 vanilla js 訪問的“文檔”是什么,并且缺少所需的元素。我是否需要將其他內容傳遞給 angular.element 參數?嘗試了一些像 angular.element('div#pageWrapper') 這樣的選擇器作為根但得到錯誤(錯誤說這種選擇器不受支持)angular.element('div#pageWrapper')Error: [jqLite:nosel] http://errors.angularjs.org/1.5.8/jqLite/nosel
查看完整描述

2 回答

?
楊__羊羊

TA貢獻1943條經驗 獲得超7個贊

該find()方法僅限于按標簽名稱查找。因此,您無法使用您顯示的方法訪問該元素。


您可以改為使用以下語法訪問元素


angular.element($document[0].querySelector('#account_name_text_field'));


// or 


angular.element(document.querySelector('#account_name_text_field'));

其中$document是瀏覽器window.document對象的 jqLite 包裝器。


查看完整回答
反對 回復 2021-08-20
  • 2 回答
  • 0 關注
  • 301 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號