views:

716

answers:

4

Please, I have another simple question for experienced programmers.

Is it possible to get source code of any webpage with javascript at client side? With AJAX maybe?

But I need that the server I am downloading the url from does see the IP of the client.. with AJAX it will show my script server IP, right?

Thank you in advance.

+3  A: 

Javascript can not fetch items outside of its domain.

An AJAX query is just a normal request done asynchronously. Everything that happens in a real request will happen in an AJAX request.

Regarding the IP thing, the request is coming from the client. Since Javascript is client based, so you will see the client's IP in the request.

Ólafur Waage
A: 

Firstly, this is known as cross-site scripting (XSS) and is considered a security risk, so current browsers do not allow it.

More generally, if your page included a reference (an image, perhaps) sourced from server X, then server X would see the client's apparent IP, which could be a proxy server in their ISP, or their real IP.

Phil H
+2  A: 

It should be possible to do so if you implement a service on your server that does the retrieval. So your AJAX-request would call a URL like the following:

http://myownserver.com/getContent?url=theotherserver.com

That way you could get around the XSS-security protection of your browser, but the remote server will then see the IP of your own server instead of that of the client.

Benedikt Eger
A: 

How does google translation gets urls code source then?. If you check your ip with www.my-ip.com for example throught the google's translation page, it will display your ip. That means that there must be a way to get any url source code from client side, using AJAX i guess?

Jeremy