3

I'm trying to make a small snippet on Google Chrome (as a bookmark) so I can "alert" my remote ip adress, but it is not working as it gives me the following error :

XMLHttpRequest cannot load https://l2.io/ip.js?var=myip. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://stackoverflow.com' is therefore not allowed access.

var url = "https://l2.io/ip.js?var=myip" var httpRequest = new XMLHttpRequest() httpRequest.onreadystatechange = function (data) { // code } httpRequest.open('GET', url) httpRequest.send() alert(httpRequest["response"]) 

How can I get around this problem ?

4
  • Is that your server you are calling? Commented Oct 25, 2015 at 14:45
  • l2.io/ip.js?var=myip is a webpage that show your current ip address, I want to crawl it using Javascript so I can output (as an alert) my current ip address by clicking a bookmarklet, but it doesn't seem to work (for security reasons, I can't call it on every websites) Commented Oct 25, 2015 at 14:47
  • Which is why I wanted to know if it was your server otherwise you could solve it without much effort Commented Oct 25, 2015 at 14:48
  • No it's not my server Commented Oct 25, 2015 at 14:52

1 Answer 1

1

You can get around this problem in a few ways. Tampermonkey, Chrome extensions or a Chrome app.

Here is an example using Tampermonkey.

// ==UserScript== // @name Show my IP // @version 0.1 // @include /https?:\/\/*/ // @grant GM_xmlhttpRequest // @grant GM_registerMenuCommand // ==/UserScript== GM_registerMenuCommand('My IP', run); function run(){ GM_xmlhttpRequest({ method: "GET", url: "https://l2.io/ip.js?var=myip", onload: function(response) { alert(response.responseText); } }); } 

This adds a menu option to the tampermonkey plugin called "My IP" that when you click it, it shows the alert box.

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.