简体   繁体   English

如何使用javascript隐藏特定网页上的按钮?

[英]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. 窗口弹出功能取决于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: 您需要将sunction称为ONLOAD:

-I set a variable "preventpop" to prevent window to pop automatically. -我设置了一个变量“ preventpop”以防止窗口自动弹出。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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