1

is it possible to fire the execution of a script in the background via click?
I am within a CMS/CRM and want to trigger an external file to load when clicking on a certain link within the CMS/CRM.

e.g. activate the php.mailer to send an email.

It seems to be a security issue when using (cross domain vulnerability?)

foobar.onload()

and if it weren't, it would not execute the file in the background. I have seen that it was solved in python using with

subprocessor()

.

The external script would be on my domain though and not touch the CMS / CRM.
Any ideas?

leopold
  • 1,971
  • 1
  • 19
  • 22
  • 1
    Take a look on Access-Control-Allow-Origin header http://stackoverflow.com/questions/10636611/how-does-access-control-allow-origin-header-work – mvladk Jun 14 '15 at 13:47

2 Answers2

1

In JavaScript you can't access to the filesystem, but you can use ajax to request some url with differents methods (GET, POST...).

The script you called from the url can execute a function to send an email if you want.

If you know jQuery, you can do something like that in JavaScript

$.get("myScript.php");

And in your myScript.php file :

mail('you@mailhost.com', 'Hello', 'Cool !');

And if your php script is not on the same domain, you should check Access-Control-Allow-Origin header that allow your client (the browser which execute the ajax script) to call the remote php script

eroak
  • 1,017
  • 10
  • 17
  • Thanks! While I could not apply this solution within the current CRM. Your answer helped me with another :) – leopold May 31 '16 at 20:54
0

You could have your click event handler make an AJAX request. For example:

myButton.onclick = function (e)
{
    // Make an AJAX request with jQuery
    $.get('/ajax/getFoo.php', function (data)
    {
        // This runs when the AJAX call returns
    });
}

Alternatively, you might look at the jQuery .load() function too:

http://api.jquery.com/load/

Richard
  • 4,809
  • 3
  • 27
  • 46