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();
<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>';
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.