0

I am really sorry if the question already exists, but I have been searching everywhere for 30 minutes with no result. So I am wondering if I can see the actual javascript code, which is linked in the script tag, so I can learn from it. For example, I am really curious to take a look at this javascript code:

<script src="https://smart-ip.net/geoip-json?callback=ip_callback"></script>
Boyan Hristov
  • 1,067
  • 3
  • 15
  • 41
  • 4
    Just open it in a browser. – Darkhogg Jan 06 '14 at 23:46
  • 1
    Just plug the URL into a new tab on your browser. [Here's a link](https://smart-ip.net/geoip-json?callback=ip_callback). It's unfortunately minified, so it's hard to read unless you stick it into a text editor/IDE and have that format it. – ajp15243 Jan 06 '14 at 23:46
  • When I go to it I see the already executed javascript code as page. It looks like noboyd understood me right, I want to see the actual code, not its result. When I go to the source I get MY ip and various other information which is the "return" of this javascript, not the code... – Boyan Hristov Jan 06 '14 at 23:54

4 Answers4

2

Yes, you can. Just copy its url and paste it in your browser's address bar.

Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
Edgar Villegas Alvarado
  • 18,204
  • 2
  • 42
  • 61
  • I understand, in most cases that's valid. But if you look at this question... it's so so simple, it would be silly to explain more in the answer, I think. Cheers Bartosz – Edgar Villegas Alvarado Jan 09 '14 at 22:14
2

They are using HTML5 Geolocation or a server side alternative. You can learn more about that here for Javascript. More likely however, they are using PHP or another server side language, so you wouldn't be able to see the code for that. However, you can use the GeoIP API for PHP

scrblnrd3
  • 7,228
  • 9
  • 33
  • 64
1

viewing source in your browser

You can view the actual source inside your browser using this url:

view-source:[path_to_file]

So in your case this will be

view-source:https://smart-ip.net/geoip-json?callback=ip_callback

This works in Firefox and Chrome. Of course, you can also just download the file (paste the path in your browsers addressbar) and check it out in a texteditor like Notepad.

minified code

Probably the souce looks minified(no returns,tabs etc). You can use http://jsbeautifier.org to see more pretty indented code.

developer tools/http debugging

If seeing this url requires sessions or something, you can also run the html-page, and use chrome developer tools or firebug to see the network sources. You'll find the source passing by in the list.

Mark Knol
  • 9,663
  • 3
  • 29
  • 44
0

Yes. Go to it. Your browser is called a "user agent" for a reason. Anything it can do, you can do, roughly.

The script will likely be minified, so the Javascript will be very unreadable. In some cases (like if you're looking at an open-source website) you can find the original source. That's the limitation on this approach.

djechlin
  • 59,258
  • 35
  • 162
  • 290
  • 2
    I don't think this is what he's asking. The page that you're going to gives the user's location. He wants the code that gives the location – scrblnrd3 Jan 06 '14 at 23:47
  • @scrblnrd3 maybe. You can post that as answer if you're willing to explain client/server separation. – djechlin Jan 06 '14 at 23:49
  • I know js is server-side so you don't download the code as you do with the html, css and so on. My question was, is there ANY way of doing it, any at all. – Boyan Hristov Jan 07 '14 at 00:04