[英]Replace specific part of src attribute into an iframe element
有什么方法可以将src
属性的特定部分替换为iframe
元素吗?
我的iframe来自我正在研究的Google博客...
<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#');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.