[英]best way to insert an image in href
I am looking for the best way to insert an image with greasmonkey into a href. 我正在寻找将带有greasmonkey的图像插入href的最佳方法。 The picture should be there where now the text (??????) is. 图片应该位于现在文本(??????)所在的位置。
// ==UserScript==
// @name ...
// @description ...
// @include http://website/
// @version 1.0
// ==/UserScript==
var links = document.getElementsByClassName( 'xyz' );
for ( var i = 0; i < links.length; i++ ) {
var link = links[i];
var newlink = document.createElement( 'a' );
newlink.href = link.href.replace( 'value=10', 'value=20' );
newlink.textContent = '??????';
var nextNode = link.nextSibling;
link.parentNode.insertBefore( newlink, nextNode );
var delim = document.createTextNode( ' - ' );
link.parentNode.insertBefore( delim, newlink );
}
Thank you all for the help. 谢谢大家的帮助。
var links = document.getElementsByClassName( 'xyz' );
for ( var i = 0; i < links.length; i++ ) {
var link = links[i];
var newlink = document.createElement( 'a' );
newlink.href = link.href.replace( 'value=10', 'value=20' );
var the_image = document.createElement('img');
the_image.src = '';//Place image source file path here
newlink.appendChild(the_image);
var nextNode = link.nextSibling;
link.parentNode.insertBefore( newlink, nextNode );
var delim = document.createTextNode( ' - ' );
link.parentNode.insertBefore( delim, newlink );
}
Insert the following lines instead of the one with the ???
插入以下几行而不是带有???
: :
var myImg = document.createElement('img');
myImg.src= 'path/to/image';
newlink.appendChild(myImg);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.