0

I am trying to add a download element to the page. I click it using Greasemonkey. The new div has been added to the page but the download window is not opening.

     var iDiv = document.createElement('div');
     iDiv.id = 'block';
     iDiv.className = 'block';
     document.getElementsByTagName('body') [0].appendChild(iDiv);
     iDiv.innerHTML = '<button class=button> <a href=' + link + ' target=_blank> </button>';
     document.getElementsByClassName('button') [0].click();
Nevermore
  • 882
  • 2
  • 18
  • 44
itai
  • 1
  • 1

2 Answers2

1

<a href=http://somesite.com target=_blank> is invalid. You're missing quotes around the URL. Also, as @Springfield pointed out, you're not closing your <a> tag.

Solution :

iDiv.innerHTML = '<button class="button"> <a href="' + link + '" target="_blank">Link</a></button>';

which renders :

iDiv.innerHTML = '<button class="button"> <a href="http://somesite.com" target="_blank">Link</a></button>';
Jeremy Thille
  • 26,047
  • 12
  • 43
  • 63
0

Don't wanna be rude, but first questions first: Where does your anchor-tag end?

You open an a-tag, but its content as well as the end tag are both missing.

springfeld
  • 89
  • 8