I am using ASP Classic with JavaScript for my web pages. I need to set a session variable onbeforeunload, which is the page's URL so we can return the user back to the page they were on if they're redirected to login or whatnot. Its not working and I need the help to figure why its broken in those browsers.

It works perfect is FF 3.*, IE 6, IE 7, & IE 8
Does NOT work in: Safari 5.*, FF 4.0, & Google Chrome 10.*

I have 3 files: header.asp, miscfunctions.js, and miscvariables.asp, and the landing page.

Landing page, will either have a Response.Redirect or a link that will have the redirectPage variable for the URL (which, in header.asp, sets the default if there is no value for the session).

RIGHT NOW it doesn't even seem to execute the AJAX, nor does it redirect to the default pages. I've tried Googling, but the most I get are people complaining their alerts don't work, or they're using ASP.NET or PHP which doesn't really help me. Not really my issue here, for the most part anyways. if I add a return, I end up with a pop up message, which I DO NOT want. I just need to set the session variable of the current page whenever someone navigates to another page on the site.

Here's my code:

header.asp:
Code:
<%
// ---------------- START SESSION CODE ---------------- //

//This script gets the URL of the current page, then extracts the file name and path from the URL
var sURL = Request.ServerVariables("URL")+"";    // get current URL in plain ASCII
if(sURL != Session("PrevPage"))
{
	var LastPage = sURL.replace("/","");
	if(Request.ServerVariables("QUERY_STRING") != "" && String(Request.ServerVariables("QUERY_STRING") != "undefined"))
	{
		LastPage += "?"+Request.ServerVariables("QUERY_STRING");
	}
	if(Session("bDebug") == true) // if on testing servers
	{	// send message to page, displaying Session Previous Page and Current URL
		Response.Write("<br /><font style='font-size:10px; color:#ffffff;'>[Session: "+Session("PrevPage")+" | Full URL: "+rootPath +LastPage+" | Current URL: "+sURL+"]</font>");
	}
}

var redirectPage = rootPath + "Default.asp?Consumer";
if(String(Session("PrevPage") != "undefined"))
{
	redirectPage = rootPath + Session("PrevPage") + "";
}
else if(Session("AccountType") == 2)
{
	redirectPage = rootPath + "Default.asp?Company";
}

// ------------------ END SESSION CODE ------------------ //
%>
	<script type="text/javascript">
		if("<%=sURL%>" != "/LogIn.asp" && "<%=sURL%>" != "/EditCustomer.asp" && "<%=sURL%>" != "/login.asp" && "<%=sURL%>" != "/editcustomer.asp")
		{
			window.onbeforeunload = function(){ updateSessionVar("<%=LastPage%>"); }
		}
	</script>
miscfunctions.js:
Code:
function updateSessionVar(SessionValue)
{
	var canvas = document.getElementById("ErrorBox");
	var xmlhttp = AJAXObj();
	var intNoCache = Math.floor(Math.random()*1000000001);

	xmlhttp.open("GET","/scripts/miscfunctions.asp?CMD=UPDATESVARIABLES&SessionValue="+SessionValue+"&Empty=" + intNoCache,true);
	xmlhttp.send(null);

	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==4)
		{
			var ajaxRes = xmlhttp.responseText;
			if (ajaxRes.indexOf(ajaxResErr) > -1)
			{
				canvas.innerHTML = ajaxRes;
			}
			else
			{
				canvas.innerHTML = ajaxRes;
			}
		}
	}
}

//FUNCTION FOR AJAX//
function AJAXObj()
{
	// Create XML DOM Object (AJAX).
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp = new XMLHttpRequest();
	}
	else
	{
		// code for IE6, IE5
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  	}
	return xmlhttp;
}
miscfunctions.asp
Code:
<%
// Global variables.
var CMD;
// End global variables.

if(Request.QueryString("CMD").Item)
{
	CMD = Request.QueryString("CMD").Item;
}

switch(CMD)
{
	case "UPDATESVARIABLES":
		updateSVariable(Request.QueryString("SessionValue").Item);
		break;
	default:
		break;
}

function updateSVariable(SessionValue)
{
	Session("PrevPage") = SessionValue;
	Response.Write(Session("PrevPage"));
}
%>