function FindProxyForURL(url, host) {
// …
}Proxy Auto-Configuration (PAC) file / notebook
Proxy Auto-Configuration (PAC) file
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
isPlainHostName("www.mozilla.org"); // false
isPlainHostName("www"); // truefunction FindProxyForURL(url, host) {
alert(isInNet(host, "192.0.2.172", "255.255.255.255"));
// "PAC-alert: true"
}dnsResolve("www.mozilla.org"); // returns the string "104.16.41.2"convert_addr("192.0.2.172"); // returns the decimal number 1745889538shExpMatch("http://home.netscape.com/people/ari/index.html", "*/ari/*"); // returns true
shExpMatch("http://home.netscape.com/people/montulli/index.html", "*/ari/*"); // returns falsefunction FindProxyForURL(url, host) {
if (isPlainHostName(host) || dnsDomainIs(host, ".mozilla.org")) {
return "DIRECT";
}
return "PROXY w3proxy.mozilla.org:8080; DIRECT";
}function FindProxyForURL(url, host) {
if (
(isPlainHostName(host) || dnsDomainIs(host, ".mozilla.org")) &&
!localHostOrDomainIs(host, "www.mozilla.org") &&
!localHostOrDomainIs(host, "merchant.mozilla.org")
) {
return "DIRECT";
}
return "PROXY w3proxy.mozilla.org:8080; DIRECT";
}function FindProxyForURL(url, host) {
if (isResolvable(host)) {
return "DIRECT";
}
return "PROXY proxy.example.com:8080";
}function FindProxyForURL(url, host) {
if (
isPlainHostName(host) ||
dnsDomainIs(host, ".example.com") ||
isResolvable(host)
) {
return "DIRECT";
}
return "PROXY proxy.example.com:8080";
}function FindProxyForURL(url, host) {
if (isInNet(host, "192.0.2.172", "255.255.0.0")) {
return "DIRECT";
}
return "PROXY proxy.example.com:8080";
}function FindProxyForURL(url, host) {
if (
isPlainHostName(host) ||
dnsDomainIs(host, ".example.com") ||
isInNet(host, "192.0.2.0", "255.255.0.0")
) {
return "DIRECT";
}
return "PROXY proxy.example.com:8080";
}function FindProxyForURL(url, host) {
if (isPlainHostName(host) || dnsDomainIs(host, ".example.com")) {
return "DIRECT";
} else if (shExpMatch(host, "*.com")) {
return "PROXY proxy1.example.com:8080; PROXY proxy4.example.com:8080";
} else if (shExpMatch(host, "*.edu")) {
return "PROXY proxy2.example.com:8080; PROXY proxy4.example.com:8080";
}
return "PROXY proxy3.example.com:8080; PROXY proxy4.example.com:8080";
}function FindProxyForURL(url, host) {
if (url.startsWith("http:")) {
return "PROXY http-proxy.example.com:8080";
} else if (url.startsWith("ftp:")) {
return "PROXY ftp-proxy.example.com:8080";
} else if (url.startsWith("gopher:")) {
return "PROXY gopher-proxy.example.com:8080";
} else if (url.startsWith("https:") || url.startsWith("snews:")) {
return "PROXY security-proxy.example.com:8080";
}
return "DIRECT";
}if (shExpMatch(url, "http:*")) {
return "PROXY http-proxy.example.com:8080";
}