我正在尝试创建chrome扩展,它将从网页中读取特定TAG内的文本...
但不能读取价值
我需要在标签定义中选择Text,不包括html标签..
这里我想读取标签“定义”中的值
输出:是一种压倒性的冲动,因为某些东西经常与金钱有关 假设网页是这样的
<div id="definition">
<div class="section blurb">
<p class="short"><i>Greed</i> is an overwhelming urge to have <i>more</i>
of something
<p class="long"><i>Greed</i> is often connected with money</p>
</div>
</div>
这就是我的尝试 popup.html
<script>
var newwin = chrome.extension.getBackgroundPage();
newwin.get();
</script>
background.html
<Script>
function get()
{
var myDivObj = document.getElementById("definition");
if ( myDivObj ) {
alert (myDivObj.innerHTML);
}else{
alert ( "Alien Found" );
}
}
</Script>
答案 0 :(得分:1)
我将脚本从后台页面移动到内容脚本,它就像魅力一样......
但只是想知道为什么不在后台页面工作..?