![](/img/trans.png)
[英]How to target DOM elements from new popup window, using chrome extension popup.html
[英]How to target HTML DOM elements from an external webpage using JavaScript
我已經獲得了網頁的整個HTML,並且遇到了諸如response.getElementById is not a function
重復錯誤。
這是我的代碼:
$.get('myUrl', function(response) {
storageVariable = response.getElementById('#id').textContent;
console.log(storageVariable);
})
我真正想做的是針對外部網頁的不同元素,並將它們存儲在不同的變量中。
任何幫助是極大的贊賞!
例如,如果從AJAX調用獲得HTML作為字符串,則可以使用DOMParser
API,然后對該對象使用所有document
方法:
$.get('myUrl', function(response) {
let parser = new DOMParser();
let parsedHtml = parser.parseFromString(response, 'text/html');
console.log(parsedHtml.getElementById("<something>").innerHTML);
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.