开发者

Why call iframe from JavaScript

I want to know why some ad codes or embed codes don't directly give you iframe code to embed on your site instead they give a JavaScript code which links to another JavaScript file on the开发者_如何学Goir server. The file on their server calls the iframe which serves the content. Why is this done and what are the benefits of this method.

Example: this is the code issued by Amazon:

<script type="text/javascript" src="http://www.assoc-amazon.co.uk/s/ads.js"></script>

Which opens another JavaScript file that calls the iframe.


The biggest reason I can see for using a JavaScript file is that they want to be able to access cookies stored on the path of your page. They can't do that if they're supplying an iframe directly (they would only see cookies stored in the iframe's path). It's important; those third-party cookies relative to your page give them a lot of information, and let them store information specific to your visitor and your site, in your visitor's browser cookie database.

As for why Amazon gives you a JavaScript file that sets a few variables and then includes another JavaScript file, it gives them the ability to set the variables based on what they see (perhaps that ads.js is dynamically generated on the basis of what cookies it seems), and it lets them change the other JavaScript file path as they see fit.


It is more flexible - if they decided to do something else later.

Also, JavaScript on your page has the freedom to parse the DOM and examine the content. An iframe on a different domain cannot access its parent.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜