0

So I have a JavaScript function:

function loadHelp() {
    window.location = "http://www.examplewebsite.com";
    return false;
}

No, when I click on:
<a target="_blank" href="javascript:void(0);" onclick="loadHelp()" class="btn-image help">&#32;</a> Nothing happens.

I have also tried:

function loadHelp() {
    return http://www.somewebsite.com
}

and

<a target="_blank" href="loadHelp()" class="btn-image help">&#32;</a>

but that doesn't work either.

Please help!

4 Answers 4

3

Try this instead:

<a target="_blank" href="javascript:loadHelp();" class="btn-image help">&#32;</a>

Also the one you have already works fine: http://jsfiddle.net/maniator/SW7bZ/

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

5 Comments

I had tried that too, that simply appends loadHelp() to the current directory's URL. For example if I am at www.somewebsite/somedirectory/someotheridrectory/code.seam, clicking on that button opens the URL www.somewebsite/somedirectory/someotheridrectory/loadHelp(), which does not exist.
@mahendru. you did not try that. use javascript:loadHelp()
I just tested it again, it does exactly what I said it does in my comment.
@mahendru, please post your code to jsfiddle.net so I can see exactly what you are doing
My bad, I did indeed keep on testing my old code. Thanks for your help.
0

You need to specify the full path (with protocol) i.e:

function loadHelp() {
  window.location = "http://www.examplewebsite.com";
}

Otherwise, it's treated as a relative path.

1 Comment

I do have the full path, I just typed that up for a quick example. I'll edit it in the original question.
0

I'm assuming your function loadHelp() simply needs to be defined earlier.

Uncaught ReferenceError: loadHelp is not defined

was probably your error. Check your console.

Comments

0

Did you make sure you have everything in the proper place, like the script.

<!DOCTYPE html>
<html>
    <head>
        <title>How to make a javascript link</title>
        <script type="text/javascript">
            function loadHelp()
            {
                window.location = "www.examplewebsite.com";
                return false;
            }
        </script>

    </head>
    <body>
        <a target="_blank" href="javascript: loadHelp();" class="btn-image help">Test &#32;</a>
    </body>
</html>

Comments

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.