4

How can I fix this error "missing; before statement" in javascript ?

alt text

My HTML Page : http://etrokny.faressoft.com

My Javascript Code : http://etrokny.faressoft.com/javascript.php

8
  • 5
    Please post your unobfuscated/unminified javascript code. Don't expect someone reverse engineering this stuff. It's much easier to find bugs when you post the code in a clear form. Commented Dec 16, 2010 at 8:55
  • I would start by "unminimizing" the JS, having it all in one line is making debugging almost impossible. Commented Dec 16, 2010 at 8:57
  • Does your original javascript give the same error, or is it only the minified version? Commented Dec 16, 2010 at 8:57
  • 3
    By putting a semicolon where required Commented Dec 16, 2010 at 8:58
  • @Gareth : No, it doesn't Commented Dec 16, 2010 at 8:59

3 Answers 3

4

When assigning a function to a variable, you need a semicolon after the function.

Example: var func = function() { return false; };

Sign up to request clarification or add additional context in comments.

Comments

2

Put a semicolon after all statements. JavaScript does it automatically for you when you "forget" one at the end of a line**, but since you used a tool to make everything fit on one line, this doesn't happen anymore.

** it should also be happening when a statement is followed by a }, but it's just bad practice to rely on it. I would always write all semicolons myself.

Actually, you know what, since it's so easy, I did it for you:

function getSelected() {
    var selText;
    var iframeWindow = window;
    if (iframeWindow.getSelection) {
        selText = iframeWindow.getSelection() + "";
    } else if (iframeWindow.document.selection) {
        selText = iframeWindow.document.selection.createRange().text;
    }
    selText = $.trim(selText);
    if (selText != "") {
        return selText;
    } else {
        return null;
    }
}
$(document).ready(function () {
    function scan_selectedText() {
        if (getSelected() == null) {
            return false;

        }
        if (getSelected().length < 25) {
            return false;
        }
        $(document)[0].oncontextmenu = function () {
            return false;
        };
        var result = true;
        var selected_Text = getSelected();
        selected_Text = selected_Text.replace(/ {2,}/g, ' ').replace(/\s{2,}/g, ' ');
        $('#content .para').each(function () {
            var accepted_text = $.trim($(this).text());
            accepted_text = accepted_text.replace(/ {2,}/g, ' ').replace(/\s{2,}/g, ' ');
            if (accepted_text.search(selected_Text) > -1) {
                result = false;
            }
        });
        var AllAccepted = "";
        $('#content .para').each(function () {
            var correntDiv = $.trim($(this).text()).replace(/ {2,}/g, ' ').replace(/\s{2,}/g, ' ');
            AllAccepted = AllAccepted + correntDiv + " ";
        });
        if ($.trim(AllAccepted).search(selected_Text) > -1) {
            return false;
        }
        if (!result) {
            return false;
        }
        var body = $.trim($('body').text());
        body = body.replace(/ {2,}/g, ' ').replace(/\s{2,}/g, ' ');
        var bodyWithoutDivs = body;
        $('#content').each(function () {
            var correntDiv = new RegExp($.trim($(this).text()).replace(/ {2,}/g, ' ').replace(/\s{2,}/g, ' '), "");
            bodyWithoutDivs = bodyWithoutDivs.replace(correntDiv, '');
        });
        if (bodyWithoutDivs.search(selected_Text) > -1) {
            return false;
        }
        if (body == selected_Text) {
            return true;
        }
        return true;
    }
    $(document).mousedown(function (key) {
        if (key.button == 2) {
            if (scan_selectedText() == true) {
                $(document)[0].oncontextmenu = function () {
                    return false;
                };
            } else {
                $(document)[0].oncontextmenu = function () {
                    return true;
                };
            }
        }
    });
    var isCtrl = false;
    $(document).keyup(function (e) {
        if (e.which == 17) isCtrl = false;
    }).keydown(function (e) {
        if (e.which == 17) isCtrl = true;
        if (e.which == 67 && isCtrl == true) {
            $("#content2").animate({
                opacity: 0
            }, 500).animate({
                opacity: 1
            }, 500);
            if (scan_selectedText() == true) {
                return false;
            } else {
                return true;
            }
        }
    });
    document.onkeypress = function (evt) {
        if (evt.ctrlKey == true && evt.keyCode == 67) {
            $("#content2").animate({
                opacity: 0
            }, 500).animate({
                opacity: 1
            }, 500);
            if (scan_selectedText() == true) {
                return false;
            } else {
                return true;
            }
        }
    };
    $('*').bind('copy', function (key) {
        if (scan_selectedText() == true) {
            return false;
        } else {
            return true;
        }
    });
});

Comments

1

First thing, start with the raw human-written version of your javascript, you know, the unminimized non-machine-generated version

After you've fixed you've made sure it is free from syntax errors .... and you minimize it, don't make a mistake when copy/pasting

2 Comments

This should be comment, and you don't really give any true help in this answer.
Shadow Wizard: Seems like snarky has only 1 reputation point atm which is not enough to leave comments. (50 is the entry point for that.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.