2

I am writing an app for Firefox OS mobile app and I am calling a Javascript function onClick() from a div attribute. Now, it works in the normal browser but when I am testing it in the simulator, the onClick function is not being called. The code's snippet is given below:

HTML codes:

      <script type = "text/javascript" src="app.js" defer></script>
      <script src = "jquery-2.1.1.min.js"></script>
      <script language = "javascript"></script>
      <link rel="stylesheet" type="text/css" href="app.css">
    </head>

<body>
<div id="page1" onclick = "eventListener()";>
<header id = "page1_header"> </header>        

    <div id = "page1_empty_space"></div> 

    <center id="page1_circle">
        <div class="circle"><img src='icons/page1_logo.jpg'id="page1_pic"></div>
  </center>

    <div id = "page1_a">
    <p1 id="page1_p1"> Click to Continue </p1>      
    </div>

    <footer id="page1_footer">
        <p id="page1_p"> &copy 2014</p>
    </footer>
 </div>

Javascript functions:

 function eventListener()
 {
    alert("on event listener");
    window.addEventListener = disableFirstPage();

 }
 function disableFirstPage() 
 {
     alert("disableFirstPage()");   

     timeout = setTimeout(PageJumping("page2"),5000); //Jump to Page 2

     disableTimeOut(timeout);
 }

 function PageJumping(x)
 {  
     alert("Jumping to "+x);
     window.location.hash = x; 
 }

1 Answers1

3

Since you have jQuery loaded, try use it to invoke the click event on the #page1.

Wrap the eventListener function around $(document).ready(); like this

$(document).ready(function(){
  $("#page1").on('click',eventListener());
});

//other functions continued ...
Peter
  • 6,509
  • 4
  • 30
  • 34
  • But, I want to use the onClick js function. I have a huge js codes which I tested in mozilla browser. None of those onclick functions are working right now. What am I doing wrong here from plain JS? – Syeda NoorJaha Azim Nov 26 '14 at 14:05
  • [CSP](https://developer.mozilla.org/en-US/docs/Web/Security/CSP) bans inline scripts. You have to replace all onClick with addEventListener. – kazhik Nov 29 '14 at 01:29