Thursday, 4 May 2017

I want to include node javascipt code in php file

I have a app.js file with the following code:

var embed = require('embed-video');

function go() {




   var c1 = document.getElementById('area1').value;

   var divElement = document.createElement("div");  
   divElement.id = "myDiv";  
   divElement.className = "myDivClass";  
   divElement.innerHTML = embed(c1);  
   document.body.appendChild(divElement); 
   form1.reset();
   var button = document.getElementById("remove");
   button.addEventListener("click", function() {
       divElement.parentNode.removeChild(divElement);
   });
    }

and an index.php file:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" class="hl-en not-logged-in ">
<head>
    <meta charset="UTF-8" />
    <title>Embedo</title>
      <script>

src="app.js"

    </script>
<meta name="google-translate-customization" content="293dbcc6d4a40585-2e495f68115e63cb-gd0522d114e7d11d6-e"></meta>
 </head>

 <body class="page-home" style=
 " margin-left: auto;
    margin-right: auto;
    width: 35%;background-color: #b0e0e6;">



 <form id="form1" >
        <div align="center">
            <textarea id="area1" rows="5" placeholder="embed here!"></textarea>
            <input type="button" value="add video!" onclick="go()" />
            <br />
            <input id="remove" type="button" value="start over!" onclick="remover()" />

        </div>
    </form>

</body>
</html>

When I press on add video button, it says "go is not defined". However, I have included the javascript file inside my php file. I have also done the corresponding npm install and my modules are present.



via Behrouz HEDAYATI

No comments:

Post a Comment