pass a javascript variable from an iframe to the parent frame

后端 未结 2 1826
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-20 17:31

So I have a variable in my iframe like so:

 

Now I want to pass that

2条回答
  •  南方客
    南方客 (楼主)
    2020-12-20 18:11

    Beware there seems to be a Chrome browser issue with addressing variables from webpages to or from IFRAMES. This issue appears in offline testing.

    That aside, assuming your browser actually implements basic functions of Javascript, you address your variable from your main webpage using window.myiframename.zipphone

     
    


    check variable

    DOC2.HTM contents -

     
     
     
    DOC2.HTM 
     
     
    
     
    
     
    
    
    

    DOC2.HTM

    That works beautifully even with older versions of Internet Explorer but try it when offline testing with Chrome and window.iframename.test_var appears to be undefined because of the Chrome issue.

    Anyway, look out for future versions of Chrome fixing this because it is a lot of egg on Google's face while they haven't.

    I have a work-around for this issue in Chrome offline testing.

    Thanks to Lucy24 on WebmasterWorld for helping. http://www.webmasterworld.com/google_chrome/4689258.htm#msg4689342

    This issue with Chrome arose when my javascript was being tested off line and files doc1.htm and doc2.htm are in the same folder on my PC.

    Moving the doc1.htm & doc2.htm files to a folder where I test my server side php programs, which runs using Windows Internet Services Manager means I can address the files using h t t p : / / l o c a l h o s t addresses and bingo, Chrome behaves as it should have behaved in offline mode.

    It is not "legitimate" in my opinion for Chrome's javascript not to be able to directly address files in the same offline folder.

    There's absolutely no security issue when you are running your own javascript files on your own PC. Or if Chrome wanted to offer a security setting that allowed or disallowed offline IFRAME variable scoping then OK, that would be fine.

    The error message is not at all clear I submit and Lucy24 did well to figure out what it meant.

    If Internet Explorer and Firefox etc allow you to test your javascript offline then why not Chrome?

    So well done Lucy24. Not so well done Chrome.

提交回复
热议问题