当JS更新时,iFrame无法正常显示

时间:2015-04-17 00:33:02

标签: javascript jquery html iframe

出于某种奇怪的原因,当使用JavaScript更新时,iFrame没有显示正确的内容。它是完全相同的链接,但结果不同

https://jsfiddle.net/omarjuvera/qvbpcy9k/1/

HTML

Desired result
<br/>
<iframe src="//ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&amp;OneJS=1&amp;Operation=GetAdHtml&amp;MarketPlace=US&amp;source=ac&amp;ref=tf_til&amp;ad_type=product_link&amp;tracking_id=ow-20&amp;marketplace=amazon&amp;region=US&amp;placement=B004BCXAM8&amp;asins=B004BCXAM8&amp;linkId=SK5UG2J5CK4WNOKE&amp;show_border=true&amp;link_opens_in_new_window=true"></iframe>

<br/><br/>
JavaScript update
<br/>
<iframe id=link src=""></iframe>

JS

document.getElementById("link").src = '//ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&amp;OneJS=1&amp;Operation=GetAdHtml&amp;MarketPlace=US&amp;source=ac&amp;ref=tf_til&amp;ad_type=product_link&amp;tracking_id=ow-20&amp;marketplace=amazon&amp;region=US&amp;placement=B004BCXAM8&amp;asins=B004BCXAM8&amp;linkId=SK5UG2J5CK4WNOKE&amp;show_border=true&amp;link_opens_in_new_window=true';

1 个答案:

答案 0 :(得分:2)

出于某种原因,你的&符号是&amp;放大器;只是让他们和他们。好像静态代码在内部解决了你的问题,但javascript没有。

document.getElementById("link").src = 
'//ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=US&source=ac&ref=tf_til&ad_type=product_link&tracking_id=ow-20&marketplace=amazon&region=US&placement=B004BCXAM8&asins=B004BCXAM8&linkId=SK5UG2J5CK4WNOKE&show_border=true&link_opens_in_new_window=true'