Click to See Complete Forum and Search --> : Javascript works when code saved as .htm but not as .asp


dholsinger
08-07-2003, 02:16 PM
I'm a novice javascripter with what seems like a simple problem that has totally got me stumped. I've got a simple pop-up window going with a session-long cookie which has worked well for the .htm pages I've used it on. Now I have to attach it to some .asp pages. If I hadn't tried this myself, I wouldn't believe it. So try this - save the code below (which contains no ASP) as popup.htm and again as popup.asp. When you call the .htm page (using IE 5+) the popup will function correctly. When you call the .asp page, nothing will happen.

code -----------------------------------


<html>
<head>

<script language="JavaScript">
function PopIt(){
popup = window.open("http://www.cnn.com?dn=1025","popDialog","top=1,left=1,height=320,width=260,scrollbars=no");
popup.window.focus();

}


function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
return 1;
break;
}
return null;
}

function SetCookie (name, value) {
document.cookie = name + "=" + escape (value);
}


function PopCode(){
var count = GetCookie('dnpopup')
if(count == null) {
SetCookie('dnpopup','1');
PopIt();
return 1;
}
}

</script>
</head>

<body onLoad="PopCode();">
Test

</body>
</html>


------------------------------------ code

If you view the source for both, they will be exactly the same. What causes the browser to treat the .asp page differently? Is it something in the header? How can I fix this?

Thanks!

:confused:

gil davis
08-07-2003, 04:46 PM
When you save an HTML file as ASP and just load the file off your hard drive in a browser, the browser doesn't know that it is supposed to treat the page as HTML because of the extension. The way Active Server Pages (ASP) work is that the server knows to change the MIME type in the header so that the client browser will know how to handle it.

Look for Personal Web Server (PWS) form Windows 95/98 or Internet Information Server (IIS) for Windows 2000/XP to play with ASP on your home computer.

dholsinger
08-07-2003, 10:44 PM
Sorry - I wasn't clear. I'm saving these pages to a web server and accessing them via HTTP. Good thought, though. To give you a better idea of my background, I make my living working mostly with Cold Fusion and HTML. Is this an ASP forum? Did I just swear? ;)

I know ASP runs server side (like CF), which is why this problem is so confusing to me. I don't know much about ASP, but I expect it works a lot like CF. Javascript thrown into a CF page functions just as if the client is requesting an HTML page. Doesn't ASP work the same way?


Thanks again for your responses!

dholsinger
08-08-2003, 10:05 AM
Bravissimo! That's what our cookie code used to look like before I 'simplified' it. :rolleyes:

Works great... thanks for your help!