简体   繁体   中英

JavaScript errors, but can't see why

I'm running a very simple piece of code to increment a number in a stats file.

It works, but testing it in various IE versions I get the following errors. I got inconsistent performance from IE7 and 9 and I think this might be causing it.

I'm getting a syntax error on the following piece of script.

<script type="text/javascript">

 function updateLikeCount(){

     parent.increment('likelinkspace14', <!--#include file="14stats.txt"-->, ' Likes');

}  <------------- *I get the error on this line*
</script>

And I'm also getting an error stating object expected in the following:

<body leftmargin="0" topmargin="0" onload="updateLikeCount();">

replace

parent.increment('likelinkspace14', <!--#include file="14stats.txt"-->, ' Likes');

with

parent.increment('likelinkspace14', '<!--#include file="14stats.txt"-->', ' Likes');

Assuming the code in the question is server side code rather than the code that gets delivered to the client the answer depends on the code being included.

As others have pointed out, wrapping the include output in quotes might help:

parent.increment('likelinkspace14', '', ' Likes');


This line has a double comma:

parent.increment('likelinkspace14', <!--#include file="14stats.txt"-->, ' Likes');

Without the html comment:

parent.increment('likelinkspace14', , ' Likes');

The problem is in the second parameter because is without '

Javascript parameter without ' is like a variable

try this:

<script type="text/javascript">
 function updateLikeCount(){
     parent.increment('likelinkspace14', '<!--#include file="14stats.txt"-->', ' Likes');
}  
</script>

Fron inside a script tag <!--#include file="14stats.txt"--> is considered syntax error.

Well, not quite syntax error but it is not a comment. Inside a script tag it is interpreted as:

< // less than
! // boolean inversion
-- // decrement

Since there's nothing on the left of the < operator it generates an error (among many other things which may also generate errors).

The problem is because of string parameter . You are trying to add a string parameter without quotes

try this

parent.increment('likelinkspace14', '<!--#include file="14stats.txt"-->', ' Likes');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM