Issue with Hiding generated href url

时间:2016-12-02 05:18:25

标签: jquery

I get url values like below.

<input type='text' value='' name="address" id="address" />
<button id='gen'>Generate</button>
</br></br>
<a id="mylink" href=''>Download</a>

$(function(){
     $('#gen').click(function(e){
        e.preventDefault();
        url='http://'+$('#address').val();
        $('a#mylink').attr('href', url);
    });
});

Now i am trying to hide the url of href on status bar like this

<a id="mylink" href='javascript:void(0)' onclick="location.href='" . $ajax_like_link . "'">

But at first before i generate url, it works. But after i generate url, on mouseover it shows the url with values. how to hide it.

1 个答案:

答案 0 :(得分:2)

当您将鼠标移到其上时,大多数浏览器都会查看您链接的href属性。您可以简单地将URL存储在JavaScript变量中,并在单击时使用它,如下所示:

&#13;
&#13;
$(function() {
  var url;

  $('#gen').click(function() {
      // save url
      url = 'http://' + $('#address').val();
  });

  $('#mylink').click(function(e) {
    e.preventDefault();
    // go to URL
    if (url)
        window.location.href = url;
  });
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" value="" name="address" id="address" />
<button type="button" id="gen">Generate</button>
<br/>
<br/>
<a id="mylink" href="#">Download</a>
&#13;
&#13;
&#13;