admin管理员组文章数量:1356426
I load some .js dynamically by creating a script tag and writing javascript to the .innerHTML of it.
I get this error:
SCRIPT1004: Expected ';'
develop, line 1487 character 24
This makes no sense...so I'm guessing it is reporting the line number correctly or wrong all together (I'm at least happy it made it this far with out failing out....1487 is near the end of my code ).
Firefox usually reports the correct line but it is always off by 1 line. I assumed IE9 would as well...
How can I troubleshoot. I already verified the code passes jshint which makes it even more strange that it is expecting a ;
. Jshint would have caught this if it was real.
Flying blind on IE9 pretty much.
Here is the code: w/ 10 lines above and 10 line below. Line 1487 is mented as such.
/**
*Publik
*/
var publik = {};
publik.initMenu = function( )
{
top_element = document.getElementById( 'top_new' );
bottom_element = document.getElementById( 'wrap_drop_down_new' );
top_element.addEventListener( "mouseout", mouse_out, false );
top_element.addEventListener( "mouseover", top_mouse_over, false ); // Line 1487
bottom_element.addEventListener( "mouseout", mouse_out, false );
bottom_element.addEventListener( "mouseover", bottom_mouse_over, false );
};
return publik;
}());
/* Use this to create Event on pletion of .js and remove cStart().
var event_load_js = document.createEvent("HTMLEvents");
event_load_js.initEvent( "blur", true, false );
Code containig top_mouse_over per request of Beat
/**
*MMenu
*/
var MMenu = ( function ()
{
/**
*Private
*/
var top_element,
bottom_element,
time_out_id = 0,
TIME_DELAY = 1000;
function showBottom()
{
top_element.style.border = '1px solid #cfcaca';
top_element.style.borderBottom = '3px solid #cfcaca';
bottom_element.style.visibility = 'visible';
}
function hideBottom()
{
top_element.style.border = '1px solid #faf7f7';
bottom_element.style.visibility = 'hidden';
}
function top_mouse_over()
{
window.clearTimeout( time_out_id );
showBottom();
}
function bottom_mouse_over()
{
window.clearTimeout( time_out_id );
}
function mouse_out()
{
time_out_id = window.setTimeout( hideBottom, TIME_DELAY );
}
I load some .js dynamically by creating a script tag and writing javascript to the .innerHTML of it.
I get this error:
SCRIPT1004: Expected ';'
develop, line 1487 character 24
This makes no sense...so I'm guessing it is reporting the line number correctly or wrong all together (I'm at least happy it made it this far with out failing out....1487 is near the end of my code ).
Firefox usually reports the correct line but it is always off by 1 line. I assumed IE9 would as well...
How can I troubleshoot. I already verified the code passes jshint. which makes it even more strange that it is expecting a ;
. Jshint would have caught this if it was real.
Flying blind on IE9 pretty much.
Here is the code: w/ 10 lines above and 10 line below. Line 1487 is mented as such.
/**
*Publik
*/
var publik = {};
publik.initMenu = function( )
{
top_element = document.getElementById( 'top_new' );
bottom_element = document.getElementById( 'wrap_drop_down_new' );
top_element.addEventListener( "mouseout", mouse_out, false );
top_element.addEventListener( "mouseover", top_mouse_over, false ); // Line 1487
bottom_element.addEventListener( "mouseout", mouse_out, false );
bottom_element.addEventListener( "mouseover", bottom_mouse_over, false );
};
return publik;
}());
/* Use this to create Event on pletion of .js and remove cStart().
var event_load_js = document.createEvent("HTMLEvents");
event_load_js.initEvent( "blur", true, false );
Code containig top_mouse_over per request of Beat
/**
*MMenu
*/
var MMenu = ( function ()
{
/**
*Private
*/
var top_element,
bottom_element,
time_out_id = 0,
TIME_DELAY = 1000;
function showBottom()
{
top_element.style.border = '1px solid #cfcaca';
top_element.style.borderBottom = '3px solid #cfcaca';
bottom_element.style.visibility = 'visible';
}
function hideBottom()
{
top_element.style.border = '1px solid #faf7f7';
bottom_element.style.visibility = 'hidden';
}
function top_mouse_over()
{
window.clearTimeout( time_out_id );
showBottom();
}
function bottom_mouse_over()
{
window.clearTimeout( time_out_id );
}
function mouse_out()
{
time_out_id = window.setTimeout( hideBottom, TIME_DELAY );
}
Share
Improve this question
edited Jul 13, 2012 at 16:55
asked Jul 13, 2012 at 16:46
user656925user656925
4
- Can you show the function top_mouse_over? – Beat Richartz Commented Jul 13, 2012 at 16:52
- i don't think you are taking the right aproach to generating your code. can you show the code in question that you are dynamically adding? – Ibu Commented Jul 13, 2012 at 16:53
- @HiroProtagonist Looks good to me too, I was only unsure if IE would actually report a semicolon error in the function when it was referenced in the event Handler as an error on the line of the event handler, but does not seem to be the case. Have you tried menting out the lines to see if the error goes away? Maybe it resurfaces at another point, that could give you a clue. – Beat Richartz Commented Jul 13, 2012 at 17:04
- Does this help: stackoverflow./a/9246081/1220302. Might you have a uni-code char or misspelled "function" in your dynamic code? – anAgent Commented Jul 13, 2012 at 17:06
3 Answers
Reset to default 4Copy your dynamically generated code from the browser and paste it into Notepad++ and search for "?" to see if you have any unicode characters. I'm pretty sure that the console isn't telling the truth. I've ran into this before as well.
See: https://stackoverflow./a/9246128/1220302
May not be unicode related. Could be a missing quote on an attribute onclick or other inline script. I've just run into this one. Example:
<button onclick="alert('hi') title="hello">Click me</button>
This error only occurs when parsing the js and gives error in line 1. I found this only threw a script parsing error in IE and not in Chrome. The error is:
SCRIPT1004: Expected ';'
mypage.html, line 1 character 54
Because I was using jquery.html() to inject this HTML into a DIV it did not parse it on page load and only under certain conditions - but in fact it was a script parsing error.
Recently I also faced the same issue with IE 11, so I did the below things to fix the issue.
- Open console window in IE browser by pressing ‘F12’
- Please change the IE version to 11 instead of the old version ( < IE11) from Emulation tab's document mode or right side top, there will be one drop-down having different IE versions.
- Browser will be reloaded automatically when we change the IE version
本文标签: javascriptIE9 reports missing semicolon that existsStack Overflow
版权声明:本文标题:javascript - IE9 reports missing semicolon that exists - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744064705a2584772.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论