How to use web viewer get ip?
Which IP?
You can use one of the device
library of f JavaScript to get info about your device including the IP.
Use this,
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://thunkable.github.io/webviewer-extension/thunkableWebviewerExtension.js" type="text/javascript"></script>
</head>
<body>
<script>
$.getJSON('https://api.ipify.org?format=jsonp&callback=?', function(data) {
console.log(JSON.stringify(data, null, 2));
ThunkableWebviewerExtension.postMessage(JSON.stringify(data, null, 2));
});
</script>
</body>
</html>
1 Like
Thanks.
How to use ip to know the geographic location?
Try this,
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://thunkable.github.io/webviewer-extension/thunkableWebviewerExtension.js" type="text/javascript"></script>
</head>
<body>
<script>
$.getJSON('https://api.ipify.org?format=jsonp&callback=?', function(data) {
fetch('http://www.geoplugin.net/json.gp?ip=' + JSON.parse(JSON.stringify(data, null, 2)).ip)
.then(response => response.json())
.then(data => ThunkableWebviewerExtension.postMessage(data));
});
</script>
</body>
</html>
no response.
I found that there is no need to use the web viewer, just use the web api directly:
https://api.ipify.org/?format=jsonp&callback=
http://www.geoplugin.net/json.gp?ip=
From your (@jaythemanchs ) html.
1 Like
Cool. Happy Coding
Will the ip be hidden? Or change?