Whether the "onclick" event works in sidebar?


(D) #1

Hi!

In Mozilla add-ons (created with WebExtention) I need put some button on the sidebar and add “onclik” event on it.
I wrot simple code in sidebar HTML file:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="panel.css"/>
  </head>
<body>
 <h2 style="text-align: center">Pages</h2>
 <form action="">
  <input id="bttn" type="button" value="Prev" onclick="showNext()">
 </form>
 <script src="panel.js"></script>
</body>
</html>

where file panel.js has such content:

function showNext() {
	alert("ok");	
}

But when I press button “Prev”, “alert” window, doesn’t appear.
I have tried to make even more simply and used only sidebar HTML file:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="panel.css"/>
  </head>
<body>
 <h2 style="text-align: center">Pages</h2>
 <form action="">
  <input id="bttn" type="button" value="Prev" onclick="alert("ok")">
 </form>
 <script src="panel.js"></script>
</body>
</html>

…same result (

What wrong?

P.S. sidebar is shown correctly


(Martin Giger) #2

Inline scripts (including on* event attributes) are not allowed in extensions. Add your listener in your JS with addEventListener instead.


(D) #3

Many thanks, Martin!