chrome extension popup.js is not working

对着背影说爱祢 提交于 2021-02-11 15:12:09

问题


I have a popup.html that looks like this

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <link type="text/css" rel="stylesheet" href="css/fbh-ui.css" />
    <script type="text/javascript" src="js/jq.js"></script>
    <script type="text/javascript" src="js/fbh-popup.js"></script>
</head>

<body style="width: 200px">
    <div id="fbh-main">
        <div id="fbh-popup-enabled"></div>
    </div>
</body>

And fbh-popup.js looks like this

$('#fbh-popup-enabled').html('test');

The JS should alter the content of the div but does not. I even tried a simple console.log('test') in the JS file and that didn't fire. I am at a loss.


回答1:


you have to write your code inside ready event callback

$(document).ready(function() {
  $('#fbh-popup-enabled').html('test');
});


来源:https://stackoverflow.com/questions/14785101/chrome-extension-popup-js-is-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!