将 src 属性的特定部分替换为 iframe 元素

Replace specific part of src attribute into an iframe element

有没有办法将 src 属性的特定部分替换为 iframe 元素?

我从我正在处理的 google 博客中获得了这个 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 来做到这一点?

向您的 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#');

}