有没有办法将src
属性的特定部分替换为iframe
元素?
我正在处理谷歌博客中的这个iframe ...
<iframe allowtransparency='true' id='reactions-iframe' class='reactions-iframe' expr:src='data:post.reactionsUrl' frameborder='0' name='reactions' scrolling='no'/>
当博客加载时,src
属性变为这样......
src="https://www.blogger.com/blog-post-reactions.g?options=%5BLike,+Dislike%5D&textColor=%23000000#http://www.blog-name.com/post-name.html"
因此,当博客加载时,我想将部分textColor=%23000000#
替换为textColor=%23ffffff#
。我怎么能用javascript或jQuery做到这一点?
答案 0 :(得分:1)
向您的iframe添加onLoad
个事件:
<iframe allowtransparency='true' id='reactions-iframe' class='reactions-iframe' expr:src='data:post.reactionsUrl' frameborder='0' name='reactions' scrolling='no' onLoad='changeSrc();'/>
在changeSrc()
函数中执行此代码以更改src值:
function changeSrc() {
const frame = document.getElementById('reactions-iframe');
frame.src = frame.src.replace('textColor=%23000000#', 'textColor=%23ffffff#');
}