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

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

alt text

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

My javascript code: http://etrokny.faressoft.com/javascript.php

+3
source share
3 answers

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

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

+2
source

Put a semicolon after all statements. JavaScript does this automatically for you when you “forget” the one at the end of the line **, but since you used the tool to keep everything on the same line, this no longer happens.

** , }, , . .

, , , , :

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;
        }
    });
});
+2

First, start with a raw, human-written version of your javascript, you know, an unimimized non-automatic version

After the correction, you are convinced that it is free from syntax errors ... and you minimize it, do not make mistakes when copying / pasting

+1
source

Source: https://habr.com/ru/post/1780635/


All Articles