My server, server.example.com, isn't accessible from the Internet. However, there's an accessible HTTP proxy, proxy.example.com, that can talk to the server.
If users configure their browser to go through proxy.example.com for *.example.com, or use a proxy autoconfig file I supply, they can access the server (after authenticating with the proxy). I want to avoid making them go through this manual process.
Is it possible to do this programmatically? The JavaScript will be served from an Internet-accessible www.example.com site, so there doesn't seem to be a security issue which would make this impossible in principle.
My constraint is that proxy.example.com is an HTTP proxy and I cannot touch it. I only control server.example.com and www.example.com, and my web app can only be run on server.example.com.
No, but...
This is not possible in the way you asked it. However, the same can be accomplished by using an iframe that opens an address of an URL chaining proxy. In your example, you have to call the following address (if your proxy allows URL chaining)
http://proxy.example.com/http://server.example.com
i hope that helps.
cheers, michael
No, you cannot set the proxy by Javascript.
there doesn't seem to be a security issue
Arbitrary Javascript altering browser settings IS a security issue.
来源:https://stackoverflow.com/questions/6988441/can-client-javascript-use-its-own-http-proxy