Bhargav Chudasama
Bhargav Chudasama

Reputation: 7161

<a href="javascript:void(0);" download>download</a> stop downloading

my problem is when <a> tag has no link so how to stop download when click on link

for example:my link is below

<a href="javascript:void(0);" download>download</a>

so when i click on below link download a void(0) file

but i want to stop downloading when <a> tag ha no link and href=javascript:void(0)

Upvotes: -1

Views: 9250

Answers (4)

Ria Nanda Jasuma
Ria Nanda Jasuma

Reputation: 1

$('a.demo').click(function(e) {
      e.preventDefault();
      //this stop default prevent or action
      //or you can use 
      e.stopPropagation();
 })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="javascript:void(0);" class="demo" download>download</a>

Upvotes: -1

Bhargav Chudasama
Bhargav Chudasama

Reputation: 7161

yes i have solve problem with <?php condition

if variable have no value than create <a> tag with no download option and if variable have value create <a> tag with download

Upvotes: -1

Bhautik
Bhautik

Reputation: 11282

just remove download attr from your tag

<a href="javascript:void(0);" class="classname">download</a>

or you can use jquery

$('tag.classname').on('click', function(e) {
  e.preventDefault();
  //this stop default prevent or action
  or you can use 
  e.stopPropagation();
})

$('a.demo').click(function(e) {
      e.preventDefault();
      //this stop default prevent or action
      //or you can use 
      e.stopPropagation();
 })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="javascript:void(0);" class="demo" download>download</a>

or with javascript

document.getElementById("demo").addEventListener("click", function(e){
    e.preventDefault()
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="javascript:void(0);" id="demo" download>download</a>

Upvotes: 1

Mohanraj
Mohanraj

Reputation: 4200

Write a click event handler and prevent the default events like below,

$('a#id-of-it').on('click', function(event) {
  // Do whatever you want
  event.preventDefault();
})

And the html looks like,

<a href="#" id="id-of-it">Download</a>

Upvotes: 1

Related Questions