Javascript: Sample Code

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.

Chrissy is a PowerShell MVP who has worked in IT for nearly 20 years, and currently serves as a Sr. Database Engineer in Belgium. Always an avid scripter, she attended the Monad session at Microsoft’s Professional Developers Conference in Los Angeles back in 2005 and has worked and played with PowerShell ever since. Chrissy is currently pursuing an MS in Systems Engineering at Regis University and helps maintain RealCajunRecipes.com in her spare time. She holds a number of certifications, including those relating to SQL Server, SuSE Linux, SharePoint and network security. She recently became co-lead of the SQL PASS PowerShell Virtual Chapter. You can follow her on Twitter at @cl.

Posted in General
2 comments on “Javascript: Sample Code
  1. hope says:

    i want to be a programmer but i need help dealy

  2. mache says:

    how to do a program about varsity players record.pls help me

Leave a Reply

Your email address will not be published. Required fields are marked *

*