开发者

What causes Javascript to act differently on different machines?

I just added a feature to a forum and while most users see and use it, a small number of people report strange behavior. I thought the problem might be due to browser caching and a ctrl+F5 solved it for some, but some can't fix it. (It's a simple editor button.)

I feel stupid even asking this but is there any way JS could not work on some machines the way it should?

EDIT: code added:

    insertTab: function()
{
    if( this.get_selection() == "" )
    {
            var val = prompt( "How many lines of tablature?", '');
            if( val == '' ) return true;

            val = parseInt(val);

            var txt = "[code]\n";

            while ( val > 0 )
            {
                txt += "------------------------------------------------------------------------------------------------" + "\n";
                txt += "------------------------------------------------------------------------------------------------" + "\n";
                txt += "------------------------------------------------------------------------------------------------" + "\n";
                txt += "开发者_开发知识库------------------------------------------------------------------------------------------------" + "\n";
                txt += "------------------------------------------------------------------------------------------------" + "\n";
                txt += "------------------------------------------------------------------------------------------------" + "\n";
                txt += "\n";

                val--;
            }

            this.insert_text( txt + "[/code]" );
    }
    else
    {
        this.wrap_tags_lite( '[code]', '[/code]', 0);
    }
}

It works perfectly on every computer I've tried personally.


Unfortunately its not really the machines that is causing the problem, most likely it is the browsers. Javascript runtime engines are implemented a little bit differently in all of the browsers so you can get slightly different behavior out of each.

IE, WebKit, and Mozilla all behave a little bit differently. When you are testing your code, you need to test on all browsers. Another option is to use a library like JQuery which somewhat abstracts some of the nuances out of javascript cross-browser programming.


This answer is specifically for addressing the cache issue, I can't say much on the "other" behavior without seeing the code.

When you change your script, either in an automated build process (if at all possible) or manually, you can update your script references, for example look at this page (I removed type="" for brevity)

<script src="http://sstatic.net/js/master.js?v=ad53a2ffc630"></script> 

It used to be a number, the changeset of the checkin or something, I'm not sure of the source, and it doesn't matter really, as long as it updated when the build changes. I assume it's some sort of hash now, which is even smarter, users won't re-download it on a version change if that file didn't change.

The important part is that it does change when the file does, and because of the querystring the browser will re-download the file, eliminating the need for Ctrl+F5.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜