Better language to interact with an external javascript

1

I am making a web page where I must use information from an external page, for this I need the page to connect with the external page with a user and its password and obtain the data that the page shows me.

I have knowledge in Java but not in Javascript so I was recommended to use PhantomJS , since the external page works with a javascript to enter, but I have had problems using the program and it is difficult even more to upload it to a web.

Will there be another language that allows to execute external javascript files and obtain information?

I thought that AJAX could work but I do not know if it has the ability to execute javascript external%.

    
asked by Bruno F 17.08.2016 в 16:11
source

1 answer

1

From your own script (in javascript, in the browser especially) you can load and invoke other scripts, as long as you do not limit access permissions (CORS).

Two examples: jQuery.getScript that, in addition, if the script load was successful, allows you to execute your own function as a callback.

Another example is the codes to load google analytics or the SDK of facebook and twitter on a page. Let's take one as an example:

// esta es una función anónima que se invoca inmediatamente "IIFE"
(function(d, s, id){
     /* primero busca un elemento con la etiqueta <script> */
     var js, fjs = d.getElementsByTagName(s)[0];
     /* si encontró un elemento con el id facebook-jssdk, aborta */
     if (d.getElementById(id)) {return;}
     /* en caso contrario, crea un <script> con el id ya dicho */
     js = d.createElement(s); js.id = id;
     /* y le asigna la url desde lo va a cargar a: */
     js.src = "//connect.facebook.net/en_US/sdk.js";
     /* y lo inserta en el documento, haciendo que el navegador lo cargue */
     fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));
// esta última línea te muestra los argumentos con que se invoca la función

Finally, I recommend you read about access control , if you're in the same host you can load scripts of it easily, but if you want to load from another host, you have to configure the permission headers.

    
answered by 17.08.2016 в 22:46