/    Sign up×
Community /Pin to ProfileBookmark

Get Server Type.

Hello all. I am new here, so please bear with me.

I have an app that contains both VBscript and Javascript. I need to be ablel to use javascript to determine the Sever Type (IIS or NON IIS) to direct users to the correct pieces of code to run given a certina situation.

I know how to do this with vbscript, but if this site gets hosted on Apache as well (which we think is likely), we need the server type.

Thanks.

pcDoctor

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@FangMar 23.2009 — JavaScript can not get server information, that requires a server side language.
Copy linkTweet thisAlerts:
@ZeroKilledMar 23.2009 — unfortunately, or fortunately, javascript don't have any kind of access to http header of document sent to browser. that is, if you load the document [noparse]mysite.com/index.html[/noparse] in browser, there is no such property (or similar) in javascript as [b]document.headers, document.getHeaders()[/b]. nothing.

however, you can use XHR (XMLHttpRequest) and request a single file, it can be empty and then read the header 'server':
<i>
</i>var xhr = new XMLHttpRequest();
xhr.open('get', '/file.txt', true);
xhr.send(null);
var server = xhr.getHeader('Server');


you will get a string that identify the server. the code is just for demonstration purpose, you have to fix it according to the browser.
×

Success!

Help @pcDoctor spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...