0

I have a webpage on which there is a link . When the user clicks on that link it popup a window. The window popup functionality depends on the name of the url.

I don't want to show the link for some webpage but not able to hide the link on page load. I used this code =

 document.getElementById('size').style.visibility='hidden'; 

but the problem with this code is when user clicks on the link it hides itself but if the user not clicks on the link it remains visible.

The code for window popup is-

<script type="text/javascript">
 //<![CDATA[
function call(id){
 var link = window.location.href ;
  var e = document.getElementById(id);
  var jockey = link.match("jockey");
     var vest = link.match("vest");
      var shorts = link.match("shorts"); 
      if((jockey =="jockey") && (vest =="vest")){          
         document.getElementById('size').style.visibility='hidden';
       } 
          else if((jockey =="jockey") && (shorts =="shorts")){
          littleWindow = window.open("http://niraame.com/media/wysiwyg/jockeyBoxerFP05.jpg", " " ,"location=center,width=520,height=520 ,toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left "); 
        } 
 //]]> 
</script>

Code to display the button-

<div id="size">
 <p><strong><a href="javascript:call()">Size Chart</a></strong></p>
</div>  

Click here to see the website

1
  • Try style.display = noneinstead of using visibility and see if that helps. Commented Jun 16, 2015 at 10:38

2 Answers 2

1

If you're looking to also hide it on page load you could try something like this:

<script type="text/javascript">
    function init() {
         document.getElementById('size').style.visibility='hidden';
    }
    window.onload = init;
</script>
Sign up to request clarification or add additional context in comments.

Comments

0

You Need to call the sunction ONLOAD:

-I set a variable "preventpop" to prevent window to pop automatically.

function call(id,preventpop){
    var link = window.location.href;
    var e = document.getElementById(id);
    var jockey = link.indexOf("jockey")>0;
    var vest = link.indexOf("vest")>0;
    var shorts = link.indexOf("shorts")>0;
    if(jockey && vest){
        document.getElementById('size').style.visibility='hidden';
    }
    else if(!preventpop && jockey && shorts){
        littleWindow = window.open("http://niraame.com/media/wysiwyg/jockeyBoxerFP05.jpg", " " ,"location=center,width=520,height=520 ,toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left ");
    }
}
window.addEventListener("load",function(){call("",true);},false);

5 Comments

It hides the link permanently for every thing. But i only want to hide the link when if(jockey && vest){ } this is true.
Hi, there was an error. I fixed it, sorry, now it should work.
It hides the button for every webpage but i want to hide it only when the first if block is true. How to achieve that?
It works for me... it hides the button only if the url contains the strings "jockey" and "vest". and the pop-up will only pop if the url contains the strings "jockey" and "shorts".
1) "example.com/jockey/vests" = HIDE button - no POP; 2) "example.com/jockey/shorts/" = SHOW button - yes POP; 3) "example.com/jockey/ubderware/" = SHOW button - no POP;

Your Answer

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