0

I have the href: <a class="like_counter_wrap fl_l" onclick="openFullList();">

I need to hide the function openFullList();. How to do this?

Ok, the code:

<!--Vk.com-->
<div class='scVK scSB'>
<script type='text/javascript' src='http://userapi.com/js/api/openapi.js?49'></script>
<script type='text/javascript'>VK.init({apiId: 2010456, onlyWidgets: true});</script>
<div id='vk_like'></div>
<script type='text/javascript'>
VK.Widgets.Like('vk_like', {type: 'button', height: 20});
</script></div>

is forms <a class="like_counter_wrap fl_l" onclick="openFullList();">. The idea is to prevent function "openFullList();"

9
  • 1
    What you mean with "hide the function"? Remove it? Commented Oct 7, 2014 at 16:29
  • Okay, and why do you need to do this? What's your intent? Commented Oct 7, 2014 at 16:30
  • Yes, I want remove it some how. Commented Oct 7, 2014 at 16:31
  • There is a list, that opening when i click the link. I don't want that this list will be opened. Commented Oct 7, 2014 at 16:32
  • 1
    "get a reference to the a", not all a elements. Commented Oct 7, 2014 at 16:36

3 Answers 3

2

JavaScript is client side code, meaning ALL code is viewable by somebody in a browser, as long as they dig deep enough. Sure, you could minify it like tyme suggests, but be aware one can still use a tool like the Chrome web inspector to find the exact line number and snippet of code run for the click event.

Basic answer: if the flow of how your code runs must not be "visible" to the end client, JavaScript is not the language you want to be using.

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

2 Comments

If I am wrong correct me, From comments, he wants to prevent calling the function openFullList() on onCLick event. I dont think he wants to hide any code to end client. Is @Alex answer related to this question...
Yes. Don't meter if the user go to the chrome inspector. The function mustn't be work.
1

You can change your markup to this

<a class="like_counter_wrap fl_l">

now you wrap your function in a script tag and place it before the closing tag body (for performance)

<script>
    function openFullList(){
         //do something
    }

    var button = document.querySelector(".like_counter_wrap");// document.querySelector("a"); 

    button.addEventListener("click",openFullList,false);
<script>

or put it in a file and bind it to your HTML like this

<script src="script/myscript.js"></script>

Comments

0

Hi what if you do like below,

   <a class="like_counter_wrap fl_l" onclick="openFullList(true);">link1</a>
   <a class="like_counter_wrap fl_l" onclick="openFullList(false);">link2</a>

then script as follows,

function openFullList(val) {

    var showList = val;
    if (showList)
    {
       //allow your function to execute
    }
    else
        return false;     //dont allow the function to execute simple by returning false

}

So, If you want to show list if user clicks on the link then pass true while calling the function or else pass false...hope it helps...

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.