-1
var clickable = ApplyClickableLinkToClass($j(".rc_blueBtn"));
setTimeout(clickable, 1000);

But if I call it like this there is no script error pop up :

ApplyClickableLinkToClass($j(".rc_blueBtn"));

The method is as follows :

ApplyClickableLinkToClass = function(selectedElements) {
    // Go through each of the passed in selections and try to apply a link to them
    $.each(selectedElements, function() {
        var linkElement = $("a:first:not(.do-not-apply-clickable-link)", $(this));
        var link = linkElement.attr("href");
        if (!IsNullEmptyOrUndefined(link)) {
            $(this).click(function(firstLink) {
                var divToLink = firstLink;
                return function() {
                    $(divToLink).unbind('click');
                    if (divToLink.attr("target") != "_blank") {
                        window.location = link;
                        return false;
                    }
                };
            }(linkElement));
        }
    });
}

The error is just a js popup "An error has occured in the Script on this page"

1
  • If you use FireBug (FireFox) or IE 9's F12 you can get better diagnostics. Commented Mar 15, 2012 at 21:04

2 Answers 2

2

Your clickable variable is set to the return value from calling the ApplyClickableLinkToClass function, which is undefined. So by passing clickable to setTimeout you're passing undefined.

Try this:

setTimeout(function() {
   ApplyClickableLinkToClass($j(".rc_blueBtn"))
}, 1000);

// OR

var clickable = function() {
   ApplyClickableLinkToClass($j(".rc_blueBtn"))
}

setTimeout(clicable, 1000);
Sign up to request clarification or add additional context in comments.

1 Comment

also can you see what that function is supposed to do, because it doesnt open links in a new windowe because thats what I expected
0

setTimeout() expects the first argument to be a function, or the source code you want to execute, as a string (this version is generally deprecated). But you're passing in the result of your ApplyClickableLinkToClass() function, not the function itself.

You want something like:

var clickable = function() {
    ApplyClickableLinkToClass($j(".rc_blueBtn"));
};
setTimeout(clickable, 1000);

1 Comment

And does this still actually run the ApplyClickableLinkToClass function ?

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.