Read meta with javascript

Asked

Viewed 22 times

0

Many google Aces use javascript to work, in authentication they use <meta name="google-signin-client_id" content="api-key"> and javascript reads this to authenticate, as they do for Javascript to read this?

1 answer

1


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

To read the example you have indicated you can do so:

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

What this code does, by steps:

  • document.querySelector - search the page for an element that matches the selector passed, where the attribute name was: _"google-signin-client_id"_
  • getAttribute - fetch the value of the attribute passed to the method
  • Thanks for the help!

  • @Thecoder glad to help :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.