Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create deployable JavaScript file

Tags:

javascript

php

To give a quick example of my question, consider the JS file provided by Google to capture Analytics data that we paste in our files. How does this JS file get all the data? I want to know how to create such JS files that I can give out to others who can then run it on their own websites and yet, store data on my website server. In short, they only copy the 1-2 lines of JS in their pages and all the intended functionality would run on their website, but the data will be stored on my web server database.

How can I attach the functionality to such a JS file? I mean, how can I tell the JS file whether to collect Analytic data or show a form, etc. I am using PHP for server side processing. I did not find any good information on this so far.

Edit 1:

I wanted to add that the functionality is NOT limited just to analytics. It could be even as simple as showing a contact form that sends email to recipients, etc.

like image 936
Devner Avatar asked Jul 28 '26 20:07

Devner


1 Answers

I think you can find the answer to your question here: How to send data to remote server using Javascript

In short, you'll be able to send data to another domain using JSONP. You can achieve this also with jQuery's, $.getJson method.

like image 157
T. Junghans Avatar answered Jul 30 '26 08:07

T. Junghans



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!