Removing the reference of an anchor from an address line



  • Is there a way to remove the anchor from the address line? #anchor?

    *{
      margin:0;
      padding:0;
      text-decoration:none;
    }
    menu{
      width:100%;
      height:50px;
      background:#fff;
      line-height:50px;
      outline:1px solid #eee;
    }
    menu span{
      position:relative;
    }
    menu span:after{
      content:'';
      border:5px solid transparent;
      border-top:5px solid blue;
      position:absolute;
      right:-14px; top:48%;
    }
    menu a{
      color:blue;
    }
    menu .preview{
      background:#fff;
      outline:1px solid #eee;
      display:inline-block;
      height:50px;
      padding:0 18px;
      position:relative;
    }
    .preview .block{
      position:absolute;
      top:51px; left:0;
      width:600px;
      height:400px;
      background:#fff;
      display:none;
      outline:1px solid #eee;
    }
    .preview:hover .block{
      display:block;
    }
    .block .content{
      width:90%;
      height:90%;
      border:1px solid #eee;
      margin:15px auto;
      overflow:hidden;
    }
    .content .left,.right{
      float:left;
      height:100%;
    }
    .content .left{
      width:30%;
      background:#fff;
      position:relative;
    }
    .content .left_menu {
      position:absolute;
      top:0; bottom:0;
      left:15px; right:0;
      outline:1px solid #eee;
      width:90%;
      height:300px;
      margin:auto;
    }
    .left_menu p{
      background:#eee;
      margin:0 0 1px 0;
      padding-left:3px;
    }
    .left_menu p a{
      display:block;
      width:100%;
      height:100%;
    }
    .content .right{
      width:70%;
      background:#fff;
      position:relative;
    }
    .content .right .right_preview{
      width:300px;
      height:300px;
      background:#fff;
      position:absolute;
      top:0; bottom:0;
      left:0; right:0;
      margin:auto;
      overflow:hidden;
    }
    .news{
      width:100%;
      height:100%;
    }
    #a{
      background:red;
    }
    #b{
      background:blue;
    }
    #c{
      background:green;
    }
        <menu> 
        <div class="preview"> 
          <span><a href="">Примеры</a></span>
          <div class="block"> 
             <div class="content"> 
               <div class="left">
                 <div class="left_menu"> 
                    <p><a id="clear_anchor" href="#c">Примеры скриптов</a></p>
                    <p><a id="clear_anchor" href="#b">Новинки видео</a></p>
                    <p><a id="clear_anchor" href="#a">Последние посты</a></p>
                 </div>
               </div>
               <div class="right"> 
                 <div class="right_preview"> 
                     <div id="a" name="" class="news"></div>
                     <div id="b" name="" class="news"></div>
                     <div id="c" name="" class="news"></div>
                 </div>
               </div>
            </div>
          </div>
        </div>
    </menu>

    That leaves a trace on the armor's address line. #a,#b,#c and we have to clean this up. window.location.hash tried :

    <script>
      window.hashName = window.location.hash;
      window.location.hash = '';
    

    $(window).load(function () {
    $('html, body').animate({scrollTop: $(window.hashName).offset().top}, 2000);
    return false;});
    });

    </script>
    <script src="https://code.jquery.com/jquery-1.10.2.js">
    </script>
    <script type="text/javascript">
    function init() {
    var buttons = document.getElementById('clear_anchor');

            buttons.onclick = function() {
                history.pushState('', document.title, window.location.pathname);
            };
        }
    

    </script>

    I'm it. html



  • Just call. window.location.hash = '';

    Maybe stay. #♪ If you're not comfortable with this, you can try to do this:

    window.location = window.location.protocol + "//" + window.location.hostname +
            window.location.pathname + window.location.search
    

    But it could lead to a reset of the page.

    Or using regular expressions:

    var url = window.location.toString(); 
    url = url.replace(/#anchor/,''); 
    window.location = url;
    

    ♪ https://stackoverflow.com/questions/5129178/remove-anchor-but-not-arguments-via-javascript


    Take everything to the anchor, you can:

    window.location = window.location.protocol + "//" + window.location.hostname + window.location.hash;
    

    or so:

    window.location.pathname = '';
    

    I hope I get the question right.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2