简体   繁体   中英

How to hide a button on a specific webpage using javascript?

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

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>

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM