简体   繁体   English

如果页面被空白打开,则隐藏后退菜单按钮

[英]hide back menu button if page was opened as a blank

How to hide a back button (in nav menu) if current page was opened with target="_blank". 如果当前页面是使用target =“ _ blank”打开的,则如何隐藏后退按钮(在导航菜单中)。

in usual case this page is called as: 在通常情况下,此页面称为:

<a href="/about_us/" class="nav-li" >About Us</a>

in another case it is called with: 在另一种情况下,它被称为:

<a href="/about_us/" class="nav-li" target="_blank" >About Us</a>

The code at the target page for the back button is: 后退按钮在目标页面上的代码是:

<label class="nav-li" for="back">Back</label>
<input class='Back' id = "back" type=button value="Back" onClick="history.go(-1)">

How to hide this button if opened as blank ??? 如果打开为空白该如何隐藏此按钮???

Whole project is on Django 整个项目在Django上

Just hide the button if the history object has a length 如果history对象具有length则只需隐藏button of null 的null less than 2 . 小于2。 This could be done with a css-class, pure css or direct with JS 这可以使用CSS类,纯CSS或直接通过JS完成

[EDIT]: [编辑]:

I would add this to the onload event of the new form. 我会将其添加到新表单的onload事件中。

function init(){
  if(history.length < 2){
    document.getElementById('Back').style.display = none;
  }
}

[...]

<body onload="init()">

[...]

You should heck the history object if the length is less or equal to 1 so it haven't a history, so you can hide your btn 如果长度小于或等于1,则应扩展历史记录对象,因此它没有历史记录,因此可以隐藏btn

window.onload = function (){
     var hasHistory = history.length <= 1; //if has an history;
     document.getElementById('cacca').style.display = hasHistory ? "none" : "block";

}

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

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