The folloing javascript code does not compile.

  • Thread starter Thread starter AAaron123
  • Start date Start date
A

AAaron123

I'm trying to check that both javascript and cookies are enabled.

The folloing code does not compile.
Error message is that cc()
is not a member of 'ASP._main_master'.
Main.Master is the name of the file.

I can't find anything wrong and don't know how to check further.

1)Can you see what might be wrong?

2)Does the approach look good? I'm especially concerned that I may be
missing something in the approach.

3)Also, I wonder why I always see the // before --> so it is not taken to be
script but why isn't <!-- taken to be script?

<head runat="server">
<script type="text/javascript">
<!--
function cc()
{
/* check for a cookie */
if (document.cookie == "")
{
/* cookie is not found */

} else {
/* this sets the value to true if cookie and javascript are both
enabled*/
document.form2.scriptcookieexists.value = "true";
}
}

/* Set a cookie to be sure that one exists.*/

document.cookie = 'killme' + escape('nothing')
// -->
</script>

</head>
....

document.cookie = 'killme' + escape('nothing')
// -->
</script>

....
<body onload="cc()">
....
form id="form2" >
<input type="hidden" name="scriptcookieexists" value="false"/>
</form>
 
Let's see:

1. You have a script block end after the </head>. Boot it from your code
2. Add language="Javascript" to the <script> block. Not critical, but good
form
3. I would also put a semi-colon after cc() in the onload. Also not critical

<head runat="server">
<script language="javascript" type="text/javascript">
<!--
function cc()
{
/* check for a cookie */
if (document.cookie == "")
{
/* cookie is not found */

} else {
/* this sets the value to true if cookie and javascript are both
enabled*/
document.form2.scriptcookieexists.value = "true";
}
}

/* Set a cookie to be sure that one exists.*/

document.cookie = 'killme' + escape('nothing')
// -->
</script>

</head>
<body onload="cc();">
<form id="form2" >
<input type="hidden" name="scriptcookieexists" value="false"/>
</form>
</body>
</html>

I see you are using the 4 guys from Rolla script. There are others. Example:

function are_cookies_enabled()
{
var cookieEnabled = (navigator.cookieEnabled) ? true : false;

if (typeof navigator.cookieEnabled == "undefined" && !cookieEnabled)
{
document.cookie="testcookie";
cookieEnabled = (document.cookie.indexOf("testcookie") != -1) ? true :
false;
}
return (cookieEnabled);
}

Much of what works and doesn't is based on the type and version of browser.

--
Gregory A. Beamer
MVP: MCP: +I, SE, SD, DBA

Blog:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think Outside the Box! |
********************************************
 
I'm still looking and notice I use name but changing to id didn't help.
I changed below.

AAaron123 said:
I'm trying to check that both javascript and cookies are enabled.

The folloing code does not compile.
Error message is that cc()
is not a member of 'ASP._main_master'.
Main.Master is the name of the file.

I can't find anything wrong and don't know how to check further.

1)Can you see what might be wrong?

2)Does the approach look good? I'm especially concerned that I may be
missing something in the approach.

3)Also, I wonder why I always see the // before --> so it is not taken to
be script but why isn't <!-- taken to be script?

<head runat="server">
<script type="text/javascript">
<!--
function cc()
{
/* check for a cookie */
if (document.cookie == "")
{
/* cookie is not found */
} else {
/* this sets the value to true if cookie and javascript are
both enabled*/
document.form2.scriptcookieexists.value = "true";
}
}

/* Set a cookie to be sure that one exists.*/

document.cookie = 'killme' + escape('nothing')
// -->
</script>

</head>
...

document.cookie = 'killme' + escape('nothing')
// -->
</script>

...
<body onload="cc()" runat="server" ...
form id="form2" runat="server"...
 
the error message means cc is being seen as a server side call. either you
have a runat=server on the body, or some other server control is referencing
it as a server side method.

-- bruce (sqlwork.com)
 
AAaron123 said:
I'm trying to check that both javascript and cookies are enabled.

The folloing code does not compile.
Error message is that cc()
is not a member of 'ASP._main_master'.
Main.Master is the name of the file.

As Bruce said, this is a server side code error, which means that you
are somewhere trying to access cc as it was a server side object.
I can't find anything wrong and don't know how to check further.

1)Can you see what might be wrong?

2)Does the approach look good? I'm especially concerned that I may be
missing something in the approach.

3)Also, I wonder why I always see the // before --> so it is not taken to be
script but why isn't <!-- taken to be script?

The start tag of the comment is ignored in the script, so that you can
put an html comment around the code without using a Javascript comment
before the start tag.

However, the html comment around the script is something that was used
back in the days when there were browsers that didn't know about the
script tag, e.g. Internet Explorer 1.0. There are no such browsers
around any more, so there is no point in using the html comment in the
script tag.

(If someone would actually install such an old browser and go to your
site, it would really look like crap anyway...)
 
Gregory A. Beamer said:
Let's see:

1. You have a script block end after the </head>. Boot it from your code

Not in the code - just the post. Sorry.

thanks
 
So a server control onload raises a server side event but if it is a client
side element onload runs script. Is that correct?

I need the runat server in the body element so I need a different approach
to see if both javascript and cookies are enabled.

A Server side approach might be more straight forward for me.

Thanks
 
Göran Andersson said:
As Bruce said, this is a server side code error, which means that you are
somewhere trying to access cc as it was a server side object.


The start tag of the comment is ignored in the script, so that you can put
an html comment around the code without using a Javascript comment before
the start tag.

However, the html comment around the script is something that was used
back in the days when there were browsers that didn't know about the
script tag, e.g. Internet Explorer 1.0. There are no such browsers around
any more, so there is no point in using the html comment in the script
tag.

(If someone would actually install such an old browser and go to your
site, it would really look like crap anyway...)


Thanks, As I told Bruce

I need the runat server in the body element so I need a different approach
to see if both javascript and cookies are enabled.

A Server side approach might be more straight forward for me.

I'll look for that now.

Thanks


PS I also wondered if
A server control onload raises a server side event but if it is a client
side element onload runs script. Is that correct?
 
AAaron123 said:
Thanks, As I told Bruce

I need the runat server in the body element so I need a different approach
to see if both javascript and cookies are enabled.

So, the code that you posted is not the code that you are using...

It's slightly easier to find the problem in the code that is actually
used where the problem is, compared to finding the problem in some other
code that is not used where the problem is not... ;)
A Server side approach might be more straight forward for me.

I'll look for that now.

Thanks


PS I also wondered if
A server control onload raises a server side event but if it is a client
side element onload runs script. Is that correct?

Yes.

You can add the onload attribute from code behind.

Markup code:

<body id="Body" runat="server">

Code behind:

Body.Attributes.Add("onload", "cc();");
 
Göran Andersson said:
So, the code that you posted is not the code that you are using...

It's slightly easier to find the problem in the code that is actually used
where the problem is, compared to finding the problem in some other code
that is not used where the problem is not... ;)

I know. It was cut (actual code) and paste (into the post) not done
correctly.

Thanks for the help
 
Back
Top