Javascript: Sample Code

Filed under: General — Written by Chrissy on Tuesday, December 12th, 2006 @ 10:42 pm

I won't lie, anytime I need Javascript stuff done, I run to my best friend & fellow programmer, Brandon. We worked on this tonight.. it's some client side javascript ajaxish action. I'll be using it for some Remote Assistance stuff I'm doing. I'm putting it here mainly for my future reference on syntax and stuff as I'm a total noob on Javascript fundamentals.

<html>
<head>
<script TYPE="text/javascript" LANGUAGE="JavaScript">
function grabVars(whichOne)
{
    if (whichOne=='workstation')
    var url = "http://roux/workstation.htm";
    else
    var url = "http://localhost/server.html";
    //multiple lines would go between brackets
    //or you can change up the technique and do
    //var url = "http://roux/grabvars.asp?mode=" + whichOne;
    //but I wanted to throw in an if/else statement there
 
    var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    xmlhttp.open("GET", url, 0);
    xmlhttp.send();
    return(xmlhttp.responseText);
    var xmlhttp = null;
}
 
function printThis()
{
  document.open();
  document.write(grabVars('workstation'));
  document.close();
}
</script>
</head>
<body onLoad=printThis();></body>
</html>

One thing...if you attempt to use this code and you try to load up an URL on the Internet (ie. a fully qualified domain name) instead of a local server, you'll receive the error: msxml3.dll error '80070005' Access Denied. There's probably a fix but I'm only calling local servers so it's okay in my case.

Also, I did initially get an IE pop-up that asked me to approve Blocked Content so when I put this out on the Intranet, I'll have to ask for a GPO modification that enables "Allow active content to run in files on My Computer" (usually found in IE -> Tools -> Advanced Settings). Setting IE parameters in GPO, FYI, is set at Start -> Run -> gpedit.msc -> User Config -> Windows Settings -> Internet Explorer Maintenance -> Security -> Security Zones and Content Rating -> Import Current Settings.

  -

No comments yet. Be the first to comment this post.

Leave your comment