Read goal with javascript

0

Many google apis use javascript to work, in authentication they use <meta name="google-signin-client_id" content="api-key"> and javascript le this to authenticate, how do they do for JavaScript to read this?

    
asked by anonymous 03.07.2018 / 14:24

1 answer

1

You can use document.querySelector to select elements from the DOM / page and extract what you are looking for.

To read the example you indicated you can do this:

var apiKey = document.querySelector('[name="google-signin-client_id"]').getAttribute('content');
console.log(apiKey);

What this code does, step by step:

  • document.querySelector - search the page for an element that matches the passed selector, where the name attribute: _ "google-signin-client_id" _
  • getAttribute - fetch this element from the value of the attribute passed to the method
03.07.2018 / 14:37