How can i change the size of an iframe from inside?

前端 未结 3 1120
-上瘾入骨i
-上瘾入骨i 2020-12-25 12:20

I\'m developing with jquery and I stumbled with the next problem: I added an IFrame inside the main page and I want to re size them from inside. I tried some ideas but witho

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-25 12:53

    If both pages are on the same domain (or even subdomain if you set document.domain maybe, did not test it) you can simply set it from javascript (or jQuery):

    window.parent.document.getElementById('myframe').width = '500px';

    If you the pages are on different domains one solution would be to to add an event listener in the page that is calling the iFrame (credits to Marty Mulligan):

    
    
        Index