Do frames and iframes have isolated javascript contexts?

后端 未结 4 1114
孤街浪徒
孤街浪徒 2021-01-04 17:27

I\'ve made some experiments in Chrome but I\'m not sure so I need a confirmation :

Am I correct in thinking that iframes and frames have a separate JavaScript contex

4条回答
  •  南方客
    南方客 (楼主)
    2021-01-04 17:51

    It's not "impossible" to share values between frames, but you have to be careful. In Internet Explorer, the following scenario will result in an error:

    1. Create a JavaScript object in frame A.
    2. Pass the JavaScript object to a function in frame B, which saves the value somewhere (in frame B)
    3. Frame A is reloaded with a new page
    4. Code in frame B attempts to reference the saved object from the (former) frame A.

    Internet Explorer does not like it when an object from a defunct page is referenced.

提交回复
热议问题