0

I would like to get the users ip, and then load it onto the properties service. But, the html file script uses javascript, not google apps script, so

<script type="text/javascript" src="https://l2.io/ip.js?var=userip"></script>

<script type="text/javascript">
   PropertiesService.getScriptProperties().setProperty(String(userip), "1")
</script> 

doesn't work. How can I make it work? Would be appreciated. Edit: context below

<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" />
    <base target="_top">

  </head>
  <body>
    `_insert webpage here_`
    <script type="text/javascript" src="https://l2.io/ip.js?var=userip"></script>
    <script type="text/javascript">
      PropertiesService.getScriptProperties().setProperty(String(userip), "1")
    </script>
  </body>
</html>
3
  • 1
    Where do you want to retrieve the IP address of the user who accessed? Where will you put <script type="text/javascript" src="https://l2.io/ip.js?var=userip"></script>? If you provide the situation of when user's ip address is retrieved, more users may be able to think of the solution of your problem. Commented Dec 19, 2017 at 0:20
  • 1
    Edited the question to include the context Commented Dec 19, 2017 at 3:24
  • 1
    You will find details on how to pass the data back to the server side in this documentation. Hope that helps. Commented Dec 19, 2017 at 20:02

1 Answer 1

1

Depending on your backend language, you can insert the value dynamically - if, say, it's PHP, you could do <%= $userIP %> in the middle of that inline JS code.

However, best practices would dictate that a) your JS code all lives in a .js file, and b) there's only three ways to properly get data from the server to the client:

  1. AJAX request from JS.
  2. HTML data-* attributes on some arbitrary element(s), read them in JS.
  3. <script type="application/json"></script>, read and parse it from JS, however this option requires special escaping of in the json body
Sign up to request clarification or add additional context in comments.

2 Comments

Ah maybe I wasn't clear enough. I'm using google apps script, which is why I tagged it with google-apps-script. Right now I'm thinking of passing the variable userid from this to my code.js file, but I have no idea how to do so.
ah, in that case i'm not sure :-/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.