2016-07-12 44 views
0

是否有任何方法將src屬性的特定部分替換爲iframe元素?將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#更換爲​​。我如何使用JavaScript或jQuery來做到這一點?

回答

1

onLoad事件添加到您的iframe:

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

}