I'm trying the example from ipify to obtain a client IP:
<script type="application/javascript">
function getIP(json) {
document.write("My public IP address is: ", json.ip);
}
</script>
<script type="application/javascript" src="https://api.ipify.org?format=jsonp&callback=getIP"></script>
This works fine.
When I try to add this into my document, nothing appears:
JS
<script type="application/javascript">
var s$ = function(e) {return document.getElementById(e);};
function getIP(json) {
s$('clientIP').innerHTML = json.ip;
}
</script>
<script type="application/javascript" src="https://api.ipify.org?format=jsonp&callback=getIP"></script>
HTML
<div>
<p><label for="clientIP">clientIP</label><span id="clientIP"></span></p>
</div>
Looking at the Chrome console, this error appears:
Failed to load resource: net::ERR_BLOCKED_BY_CLIENT
Not sure I understand why the first method works, the second does not.
<div>
<p><label for="clientIP">clientIP</label><span id="clientIP"></span></p>
</div>
<script type="application/javascript">
var s$ = function(e) {
return document.getElementById(e);
};
function getIP(json) {
s$('clientIP').innerHTML = json.ip;
}
</script>
<script type="application/javascript" src="https://api.ipify.org?format=jsonp&callback=getIP"></script>
Running this incognito, I get the following error:
Uncaught TypeError: Cannot set property 'innerHTML' of null
at getIP (VM26:10)
at api.ipify.org/:1