CodeIgniter Forums
trying to call javascript - Printable Version

+- CodeIgniter Forums (
+-- Forum: Using CodeIgniter (
+--- Forum: General Help (
+--- Thread: trying to call javascript (/thread-73547.html)

Pages: 1 2

trying to call javascript - richb201 - 05-07-2019

I realize that js is really a client thing and not a server thing. Anyway, I am trying to call 

   var editorExtensionId = "mebiphcpglaighebopfapfoiimgnnbpf";

   // Make a simple request:
   chrome.runtime.sendMessage(editorExtensionId, "snapshot_mode",
       function(response) {
           if (!response.success)

I try to load it with 

PHP Code:
I am getting:

[font=Times New Roman]A PHP Error was encountered

Severity: Error

Message: Call to undefined function javascript_funcs_extensionloaded()

Filename: controllers/Configure.php
[font=Times New Roman]Line Number: 43

Can anyone tell me how to look at this? [/font]

RE: trying to call javascript - php_rocs - 05-07-2019


Are you trying to have your web app send a browser message?

RE: trying to call javascript - richb201 - 05-07-2019

(05-07-2019, 07:03 PM)php_rocs Wrote: @richb201,

Are you trying to have your web app send a browser message?

Not really. I am trying to have the browser page send a message to the extension of the browser. There is some messaging facility in chrome. So I want the web page (which was built by the server), to make a call to the js which will send the message.

Or is that what you meant? I did ask a similar thing recently, but I am just trying to get the js to run on a page created by grocery crud or code igniter.

My overall plan is to call the aws javascript api from the extension. But I need to communicate some instructions from CI created browser page before I do that. People say that the Extension "runs in the context of the browser". I am not sure what that means, honestly, other than I can use some chrome runtime messaging feature (see the code above). But the only way I can communicate using the Chrome messaging app is to call a js function from my php created web page.

I guess the js needs to be embedded in the html but I don't know how to do that. Is the problem that I need to call register_extension() from the CI code? How does CI know I am calling a js function?

RE: trying to call javascript - richb201 - 05-08-2019

I changed the function call in my php program to


I am getting error: call to undefined function register_extension()

Now I tried:

echo "<script> register_extension(); </script>";

but need to put a debugger on the extension to see if it actually ran. 

RE: trying to call javascript - InsiteFX - 05-08-2019

Try adding the function to a var

* Document   : web-app.js
* Author     : aka (InsiteFX)
* save as : js/web-app.js

var webApp = function() {
    /* Scroll to top functionality */
    var scrollToTop = function() {

        // Get link
        var link = $('#to-top');

        $(window).scroll(function() {
            // If scrolled 150 pixels show the link
            if ($(this).scrollTop() > 150) {
            } else {

        // On click go to top of page {
            $('html, body').animate({scrollTop: 0}, 200);
            return false;
    // Initialize all functions here by name...
    return {
        init: function() {
            // Scroll to top (var scrollToTop = function(){})
            // add other functions below here.


// Initialize WebApp when page first loads
$(function() {

RE: trying to call javascript - richb201 - 05-09-2019

Thanks. How do I call it from my controller? I tried calling it from

echo "<script> webApp(); </script>";

I am getting these errors in my xdebug window:

[font=DejaVu Sans Mono]Uncaught ReferenceError: webApp is not defined[/font]
[font=DejaVu Sans Mono][font=DejaVu Sans Mono]Uncaught ReferenceError: $ is not defined[/font][/font]
[font=DejaVu Sans Mono][font=DejaVu Sans Mono][font=DejaVu Sans Mono]Uncaught SyntaxError: Unexpected token var[/font][/font][/font]

RE: trying to call javascript - InsiteFX - 05-09-2019

It already loads all the functions see the init function, then at the bottom you
can see that it loads itself.

The only way that I know how it to check the page post value then send an ajax call.

           var name = $('#name').val();
           var email= $('#email').val();
           var data = 'name=' + name + '&email=' + email;
               url: 'login_processor.php',
               type: "POST",
               data: data,
               cache: false,
               dataType: "JSON",
               success: function(data){
                       return false;
                       return false;
   $error_name = null;
   $error_email = null;
       $error_name = 'Please Enter Name!';
       $error_email = 'Please Enter Email!';
   echo json_encode(array('error_name'=>$error_name, 'error_email' => $error_email));

Something like that you need to set it up for your stuff.

The url would point to your controller method.

RE: trying to call javascript - richb201 - 05-09-2019

Thanks insite. What I really need is a document written for beginners trying to call javascript from a php generated html page. I understand the xmlhttp stuff. My extension uses that to communicate back to my server. Works great, after much pain.

I just need my web app to initiate a message to my Extension. I control bought sides. My plan is to write a .png to aws S3 directly from the extension. I could send the .png to my server and have my server upload it to S3 in php, but that would be wasteful of bandwidth, which costs $.

So if you know how I can simply get my javascript function to be called from my controller, I will work out the messaging details.

RE: trying to call javascript - InsiteFX - 05-10-2019

You can try this one out to see if it will work for you.

    <script src="test.js" type="text/javascript"></script>
    echo '<script type="text/javascript">someFunction();</script>';

You can also try to echo it from your controller.

RE: trying to call javascript - richb201 - 05-10-2019

I changed the call in my controller to:

         echo '<script type="text/javascript" > register_extension(); </script>';

I just can't tell if it is running. I put a breakpoint in my js register_extension module, but phpStorm is not stopping there. I think  my xdebug is set correctly. It seems that I don't know how to declare a javascript function in my php program. I found this is the documentation re:Javascript Class

"This library is DEPRECATED and should not be used. It has always been with an ‘experimental’ status and is now no longer supported. Currently only kept for backwards compatibility."

OK, so it was taken out Undecided.  But what do the rest of us do now?

I am getting these errors in my console:


Uncaught ReferenceError: register_extension is not defined


Uncaught ReferenceError: $ is not defined

Uncaught SyntaxError: Unexpected token var


Here is the javascript

   var editorExtensionId = "lamacgnkfoiknjpleghfknfigbmhdaei";

   // Make a simple request:
   chrome.runtime.sendMessage(editorExtensionId, "snapshot_mode",
       function(response) {
           if (!response.success)



There seems to be something BIG I am missing here? It would seem that I would need to tell the PHP program that register_extension() is a valid javascript function?