IE9 reports missing semicolon that exists

柔情痞子 提交于 2020-01-13 22:35:55

问题


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.com 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 commented 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 completion 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 );
    }

回答1:


Copy 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.com/a/9246128/1220302




回答2:


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.




回答3:


Recently I also faced the same issue with IE 11, so I did the below things to fix the issue.

  1. Open console window in IE browser by pressing ‘F12’
  2. 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.
  3. Browser will be reloaded automatically when we change the IE version


来源:https://stackoverflow.com/questions/11474812/ie9-reports-missing-semicolon-that-exists

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!