Hello Everyone, I would like to get some suggestions on a problem I am trying to address. - I send a request to a 3rd party server (for ads) and a response is received from them. - Currently, I display it inline on the page and things work fine but page loading is slow and the 3rd party response can mess up styles, js on my page. - So, I want to capture this response and dynamically generate iframes and write the response into that. This way the other site wont mess up things on my site. Now, the response is not always a simple plain gif, it could be an iframe with lots of stuff happening or it could be a URL that further calls some other ad. So, this is what I did - - Send a request to the server while the page is loading - Capture the response by overwriting default document.write() because otherwise it would open a new output stream. adContainer = ""; document.write = function(text){ adContainer += text; }; - Then dynamically create the iframe - function generateIframe(iframeId, sDocument) { var tFrame = document.getElementById(iframeId); var doc = tFrame.contentDocument; if (doc == undefined || doc == null) doc = tFrame.contentWindow.document; doc.open(); doc.write(sDocument); doc.close(); } setTimeout("generateIframe(''Left'', adContainer)", 500); Now, this works fine when I am trying to get one ad position. Add to this a situation when I want to get 5 ad positions. So, I send only ONE request. Parse the response for different positions. Create an iframe each for the positions (so like 5 iframes) and then write the responses into them. I want to know if this is the right way to do it? Sometimes when the responses are overly complicated with functions, comments, cookies, blah blah the ad doesn''t display. Please let me know your thoughts. Thanks, Mandy.
Jeremy Kitchen
2006-Jul-03 16:27 UTC
Re: dynamic generation of iframes and writing to them
On Thursday 29 June 2006 02:35, Maninder, Singh wrote:> - I send a request to a 3rd party server (for ads) and a response is > received from them. - Currently, I display it inline on the page and things > work fine but page loading is slow and the 3rd party response can mess up > styles, js on my page. - So, I want to capture this response and > dynamically generate iframes and write the response into that. This way the > other site wont mess up things on my site.> - Send a request to the server while the page is loading > - Capture the response by overwriting default document.write() because > otherwise it would open a new output stream. adContainer = ""; > document.write = function(text){^^^^^^^^^^^^^^ ack! why not just generate the iframe dynamically, then append it to your page when you''re ready? Have a div or something already in place (and styled appropriately) and use appendChild to add it. I guess basically what I"m saying is something like this (requires builder.js from scriptaculous, but is fairly trivial with normal DOM functions, I''m just lazy): var iframe = Builder.node(''iframe'', {''class'':''advertisement'', ''src'':''someurl''}); Event.observe(iframe, ''load'', function(ev) { $(''leftadframe'').appendChild(this); }.bindAsEventListener(iframe)); much prettier, and without any nasty document.write garbage :) note that here I''m assuming an iframe has an onload event, and that it fires when the content has been loaded into it :) I''m not really sure, but that should give you some ideas. document.write should die a slow, horrible, painful death. Please avoid using it at all costs. -- Jeremy Kitchen ++ kitchen-RA8HwDor7flnDGu+y90WmgC/G2K4zDHf@public.gmane.org http://www.pirate-party.us/ -- defend your rights _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Seth Dillingham
2006-Jul-03 22:27 UTC
Re: dynamic generation of iframes and writing to them
On 7/3/06, Jeremy Kitchen <kitchen-RA8HwDor7flnDGu+y90WmgC/G2K4zDHf@public.gmane.org> wrote: I guess basically what I"m saying is something like this (requires> builder.js > from scriptaculousAhem. [SNIP] document.write should die a slow, horrible, painful death. Please avoid> using > it at all costs.Which, of course, would make Scriptaculous.require die along with it. ;-) It would be nice if javascript had a built-in require or use function to load external scripts, though. THEN document.write could die it''s slow, horrible, painful death. Or we could just avoid using it (which doesn''t sound as cool). Seth _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Jeremy Kitchen
2006-Jul-06 16:31 UTC
Re: dynamic generation of iframes and writing to them
On Monday 03 July 2006 15:27, Seth Dillingham wrote:> > document.write should die a slow, horrible, painful death. Please avoid > > using it at all costs. > > Which, of course, would make Scriptaculous.require die along with it. ;-)yes, I''m aware it uses document.write, but it has a good reason to :) That doesn''t mean it should be used anywhere else though (unless it''s the ONLY way to get something done...) -Jeremy -- Jeremy Kitchen ++ kitchen-RA8HwDor7flnDGu+y90WmgC/G2K4zDHf@public.gmane.org http://www.pirate-party.us/ -- defend your rights _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs