oyvindkinsey / easyXDM

A javascript library providing cross-browser, cross-site messaging/method invocation.
http://easyxdm.net
MIT License
2.38k stars 265 forks source link

multiple remote #266

Open seaapple opened 8 years ago

seaapple commented 8 years ago

Hello,

How can I send resize information to the same iframe from two web pages? it seems that the "remote" url variable needs to be hard coded at setup time.

I'm using easyXdm socket to resize an iframe. It seems to be working on first load of the page. But I can't get it to resize when a new link is clicked from inside the iframe. Specifically when a user switches from a calendar view at 800 px high to a list view which might be 3000px high. So the new url might go from http://www.mysite.com/calendar_view/ to http://www.mysite.com/list_view/
Both pages will send back the hight information for the resize. That part is working. The problem is that the setup for the page has the remote variable hard set to http://www.mysite.com/calendar_view/ when the socket is created. So it will ignore messages sent from http://www.mysite.com/list_view/

var calendar_setup = { remote: "http://www.mysite.com/calendar_view/", container: document.getElementById("iframeContainer"), onMessage: function(message, origin){ alert('test.page got the message from calendar' + message); this.container.getElementsByTagName("iframe")[0].style.height = message + "px"; this.container.getElementsByTagName("iframe")[0].style.width = "800px"; } };

var calendar_socket = new easyXDM.Socket(calendar_setup); var runSocketMessenger = function() { calendar_socket.postMessage(); }

oyvindkinsey commented 8 years ago

You'll need to use an intermediary, or sibling frame to allow this - a search on this list should yield several examples I think. Sibling is definitely best, with your child page calling parent.xdmiframename.resizeMe. that way the xdm frame is persistent while your visible frame changes.

On Fri, Dec 11, 2015, 11:18 PM seaapple notifications@github.com wrote:

Hello,

How can I send information to the same iframe from two web pages, when the "remote" url variable is hard coded at setup time?

I'm using easyXdm socket to resize an iframe It seems to be working on first load of the page But I can't get it to resize when a new link is clicked from inside the iframe Specifically when a user switches from a calendar view at 800 px high to a list view which might be 3000px high So the new url might go from http://wwwmysitecom/calendar_view/ to http://wwwmysitecom/list_view/

Both pages will send back the hight information for the resize That part is working The problem is that the setup for the page has the remote variable hard set to http://wwwmysitecom/calendar_view/ when the socket is created So it will ignore messages sent from http://wwwmysitecom/list_view/

— Reply to this email directly or view it on GitHub https://github.com/oyvindkinsey/easyXDM/issues/266.