Asier Asier -4 years ago 149
Javascript Question

HTML5 onclick button does not works

I have this html file which must to call one function under onclick, however does not execute anything, neither alerts. I dont know what happend with this button.The button does not works is "id=botonRegistro" (any button works really).

<!DOCTYPE html>
<!-- <script type="text/javascript" src="js/jquery-2.0.2.js"></script> -->
<!-- <script type="text/javascript" src="js/"></script> -->
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript" src="js/functions_v1.js"></script>
<script type="text/javascript" src="js/objects_v1.js"></script>
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport"
content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<link rel="stylesheet" type="text/css" href="css/index.css">
<div data-role="page" id="registerPage">
<div data-role="header" align="center">
<img src="img/kirolLogo.png"> <br>
<div data-role="content" align="center" id="registerContent">
<form id="formRegistro">
<br> <input type="text" id="idNombreReg" style="border: 1;" placeholder="Nombre"><br>
<input type="text" id="idSec" style="border: 1;" placeholder="1ÂșApellido"><br>
<input type="text" id="idLast" style="border: 1;" placeholder="2ÂșApellido"><br>
<input type="password" id="idClaveReg" style="border: 1; color: orange;" placeholder="Clave"><br>
<input type="password" id="idClaveRegRep" style="border: 1; color: orange;" placeholder="Confirmar clave"><br>
<input type="email" id="idEmail" style="border: 1;" placeholder="Email"><br>
<button type="button" id="botonRegistro" onclick="alert('Registrado!')">Registrarse</button>
<div data-role="content" id="back" style="text-align: center; display: none" >
<a href="index.html" id="botonBack">Volver</a>


I have tried with


and i think that onclick does not needs prefix, so... i dont know what happend with this code, because does not calls javascript functions. Thanks

Edit: This is my css

background-image: url("../img/fondoIndex.png");
background-size: inherit
background-repeat: no-repeat;
background-position: center center;

Answer Source

I dont know why but the content security policy block it. When i delete this meta all works:

<meta http-equiv="Content-Security-Policy"  content="default-src 'self' data: gap: 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download