Omar Juvera
Omar Juvera

Reputation: 12297

iFrame is not displaying properly when updated by JS

For some weird reason, iFrame is not showing the right content when updated by JavaScript. It is the very same link, but with different results

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

Upvotes: 0

Views: 54

Answers (1)

bruceceng
bruceceng

Reputation: 2182

For some reason your ampersands are & amp; just make them &. It seems like the static code fixed the problem for you internally but the javascript did not.

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'

Upvotes: 2

Related Questions