Link to home
Start Free TrialLog in
Avatar of frosty5656
frosty5656

asked on

Change PROXY

how can i change my proxy server useing javascript
Avatar of snakehollywood
snakehollywood

You do not change this via Javascript, it is part of your browser settings.
You must goto tool --> internet options and setup your proxy server here.
Avatar of Michel Plungjan
Ns Only:

function readPref(pref) {

var targ = netscape.security.Target.findTarget("UniversalPreferencesRead");
var mgr = netscape.security.AppletSecurity.getPrivilegeManager();
mgr.enablePrivilege(targ);

return navigator.preference(pref);

}

function writePref(pref,val) {

var targ = netscape.security.Target.findTarget("UniversalPreferencesWrite");
var mgr = netscape.security.AppletSecurity.getPrivilegeManager();
mgr.enablePrivilege(targ);

navigator.preference(pref,val);
}


network.proxy.type
Sets the type of proxy server connection to use. The default is 3, which connects to Internet hosts directly, without going through proxy servers. Other values are: 1, configure proxy settings manually (using the manual proxy-setting preferences below); 2, point to an automatic proxy configuration URL containing proxy settings. If this preference is set to 2, specify the URL with network.proxy.autoconfig_url. Note that option 2 (an automatic configuration URL) doesn't apply when configuring through a centralized AutoConfig resource such as a config.jsc file.

network.proxy.http
Specifies the host name or IP address of an HTTP proxy server. The default is an empty string. If not using the default HTTP port number of 80, specify the port number with network.proxy.http_port.
network.proxy.http_port Specifies the non-default port number of an HTTP proxy server. This preference isn't needed when using the default port number of 80. The default is 0. The correct port number is determined at the server.

network.proxy.ssl
Specifies the host name or IP address of an HTTP proxy server that is accessed by SSL. The default is an empty string. If not using the default SSL proxy server port number of 443, specify the port number with network.proxy.ssl_port. This preference is lockable, applies to
Communicator 4.0 and later versions, and is available on all platforms.

network.proxy.ssl_port
Specifies the non-default port number of an SSL proxy server. This preference isn't needed when using the default port number of 443. The correct port number is determined at the server. This preference is lockable, applies to Communicator 4.0 and later versions, and is available on all platforms.
network.proxy.ftp Specifies the host name or IP address of an FTP proxy server. The default is an empty string. If not using the default FTP port number of 20, specify the port number with network.proxy.ftp_port.

network.proxy.ftp_port
Specifies the non-default port number of an FTP proxy server. This preference isn't needed when using the default port number of 20. The default is 0. The correct port number is determined at the server. network.hosts.socks_server Specifies the host name or IP address of a SOCKS server. The default is an empty string. If not using the default SOCKS port number of 1080, specify the port number with
network.hosts.socks_serverport.

network.hosts.socks_serverport
Specifies the non-default port number of a SOCKS server. This preference isn't needed when using the default port number of 1080. The default is 1080. The correct port number is determined at the server.

network.proxy.gopher
Specifies the host name or IP address of a GOPHER proxy server. The default is an empty string. If not using the default GOPHER port number of 70, specify the port number with network.proxy.gopher_port.
network.proxy.gopher_port Specifies the non-default port number of a GOPHER proxy server. This preference isn't needed when using the default port number of 70. The default is 0. The correct port number is determined at the server.

network.proxy.wais
Specifies the host name or IP address of a WAIS proxy server. The default is an empty string. There is no default WAIS port number, so it is necessary to specify one with network.proxy.wais_port.
network.proxy.wais_port Specifies the port number of a WAIS proxy server. This preference must be set when setting network.proxy.wais because there is no default WAIS proxy server port number. The correct port number is determined at the server.

network.proxy.no_proxies_on
Specifies domains to exclude when working through proxy servers. The values for this preference are formatted as a semicolon-delimited list of domains. The default is an empty string. Note that wildcards can't be used in the domain list.

network.proxy.autoconfig_url
Specifies the URL to use for automatic proxy configuration if
network.proxy.type is set to 2. The default is an empty string.
Alas I don't think NS only code is useful to anyone. Who uses NS only???
to do it with ie you will need an activex control that can write to the registry:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer  "serverName:portnumber"

<Script language="JavaScript">
try{
var wsh = new ActiveXObject("WScript.Shell")
var res = wsh.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ProxyServer", "ServerName:80"  
}catch(e){
 alert("An Error Occured: \r\n\t\t" + e.description)

}

</Script>

this is ie only - so if you mix this with the netscape solution you should be alright.
ps - win32 only - not mac ie or win3.x
Well all our staff does - so for intranet it is useful.

Why would I say "No Way" ot keep quit if there was a way for at least one browser - perhaps frosty is on an intranet... AOL and Compuserve's new browsers will be Netscape based too

For IE one would need WSH and look at

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings
ProxyServer
as gegege managed to tell before I had found the key to look at ;-)
So it IS possible.

gegege should have some points too

<html>
<head>
<title>Proxy</title>
<script>
function setNSProxy(server,port) {
   var targ = netscape.security.Target.findTarget("UniversalPreferencesWrite");
   var mgr = netscape.security.AppletSecurity.getPrivilegeManager();
   mgr.enablePrivilege(targ);
   navigator.preference(network.proxy.http,server);
   navigator.preference(network.proxy.http_port,port);
}
function setIEProxy() {
   alert('Sorry, can only be done in IE5+');
}
</script>
<script language="JavaScript1.3">
function setIEProxy(server,port) {
  try{
     var wsh = new ActiveXObject("WScript.Shell")
     var res = wsh.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ProxyServer",
     server+":"+port);  
  }catch(e){
     alert("An Error Occured: \r\n\t\t" + e.description)
  }
}
</script>

</head>

<body>

<a href="#"
onClick="
server=prompt('Server?');
port=prompt('Port',80);
if (document.all) setIEProxy(server,port);
else if (document.layers||document.getElementById) setNSProxy(server,port);
return false">Set proxy</a>

</body>
</html>
PS: If you need netscape's script to work on the net, you need to purchase a certificate and SIGN the script

Michel
Avatar of frosty5656

ASKER

is there script that will output my detected proxy so i know if it is working?

function readPref(pref) {

var targ = netscape.security.Target.findTarget("UniversalPreferencesRead");
var mgr = netscape.security.AppletSecurity.getPrivilegeManager();
mgr.enablePrivilege(targ);

return navigator.preference(pref);

}

if (document.all)
alert(wsh.RegRead("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ProxyServer")

else alert(readPref('network.proxy.http'))


and the other script also need quotes - sorry:

navigator.preference('network.proxy.http',server);
navigator.preference('network.proxy.http_port',port);
i am getting an error when i try to change proxies: "automation server can't create object" Does this script run on your cpu? if it does could you tell me what type of browser your useing? Also is the code that shows what proxy that you are useing, is that real time? and by reading the code i think it is being desplayed in an alert pop-up, is it possible to desplay that in a field? I don't know that much javascript so please bare with me. Thank You.
This work on windows NT.

NONE of the IE stuff will work on MAC!!!


<head>
     <title>Untitled</title>
<script>

function readPref(pref) {
   var targ = netscape.security.Target.findTarget("UniversalPreferencesRead");
   var mgr = netscape.security.AppletSecurity.getPrivilegeManager();
   mgr.enablePrivilege(targ);
   return navigator.preference(pref);
}


function showProxy() {
   prox = "";
   if (document.all) {
      var wsh = new ActiveXObject("WScript.Shell");
      prox = wsh.RegRead("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ProxyServer");
   }
   else prox =readPref('network.proxy.http');
   return prox;
}

</script>
 
</head>
<body>
<form name="myForm">
<input type="text" name="prox" value="">
<input type="button" onClick="this.form.prox.value=showProxy()" value="Proxy">
</form>


</body>
i still recieve the same error. I am running windows 98 on a 56kb modem, and IE 5. would it be possible to change the proxy within the javascript and it would read from a list of proxies so you would not have to enter in any values. Once it has changed to the first proxy, it will procced to the next when the function is called.
That is a corrupt IE5 installation.

Michel
don't think that IE is corrupted because i've tried it on three different computers and they all give me the same error. could there be another problem?
Do you perhaps have turned off WSH?

Michel
sorry.. but could you define WSH? Thanks.
i downloaded that program and installed it and i still recieve errors. Could you visit my web-page and tell me what i am doing wrong:

www.angelfire.com/fl5/top2002/index.html

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of gegege
gegege

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Looks remarkably like my


 try{
    var wsh = new ActiveXObject("WScript.Shell")
    var res = wsh.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ProxyServer",

    server+":"+port);  
 }catch(e){
    alert("An Error Occured: \r\n\t\t" + e.description)
 }

except the read is write.

Later I do have a read though ;-)

Michel
i know - but it looks just like the code i posted first, and i like it, so i posted it again.
Sorry. - lost my track there ;-)
Please update the experts here who have so willingly stepped in to help you, since much time has passed since your last comments, and Email notifications may not have been generated to the participating experts here due to some problems at that time.

Somewhat off-topic, but important.

****************************** ALERT********************************
WindowsUpdate - Critical Update alert March 28, 2002 from Microsoft
http://www.microsoft.com/technet/treeview/default.asp?url=/technet/security/bulletin/ms02-015.asp
Synopsis:
Microsoft Security Bulletin MS02-015  
28 March 2002 Cumulative Patch for Internet Explorer
Originally posted: March 28, 2002
Summary
Who should read this bulletin: Customers using Microsoft® Internet Explorer
Impact of vulnerability: Two vulnerabilities, the most serious of which would allow script to run in the Local Computer Zone.
Maximum Severity Rating: Critical
Recommendation: Consumers using the affected version of IE should install the patch immediately.
Affected Software:
Microsoft Internet Explorer 5.01
Microsoft Internet Explorer 5.5
Microsoft Internet Explorer 6.0

Thought you'd appreciate knowing this.
":0)
Asta