I have an iframe in which the user can browse. When they hit the ''add this page'' button i need to retrieve the url and the title of the page currently shown in the iframe. Does anyone know how to do this? Do i need to assign a variable name to my iframe? (currently it just sits in my template as a bit of html) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Max Williams wrote:> I have an iframe in which the user can browse. When they hit the ''add > this page'' button i need to retrieve the url and the title of the page > currently shown in the iframe. > > Does anyone know how to do this? Do i need to assign a variable name to > my iframe? (currently it just sits in my template as a bit of html)doing this via javascript is probably the best solution. check out the following link if the explanation below is vague: http://www.quirksmode.org/js/frameintro.html we need to pull the iframe into a js function, and from there, grabbing the url + the title should be a flip. untested code, but it should be something like the below, gathering the iframe''s attributes are <iframe name="iframe_name" src="iframe_url"></iframe> top.iframe_name.location.href # should give u "iframe_url" and top.iframe_name.document.title # should give u the iframe''s <title> hope this helps shai -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> we need to pull the iframe into a js function, and from there, grabbing > the url + the title should be a flip. untested code, but it should be > something like the below, gathering the iframe''s attributes are <iframe > name="iframe_name" src="iframe_url"></iframe> > > top.iframe_name.location.href > # should give u "iframe_url" and > > top.iframe_name.document.title > # should give u the iframe''s <title> > > hope this helps > > shaiThanks for the advice shai but this just isn''t working for me and i don''t know why. I installed firebug for firefox, which lists javascript errors (among other things) and it''s complaining "top.myframe has no properties" (myframe is the name of my iframe) I must admit i don''t even know how to take this value and do something with it in rails, so at the minute to test it i''m just doing an alert box with the returned string. But it seems to be failing while accessing the myframe object. Do you have any idea what the problem might be? Thanks again for helping by the way. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I think the "top" only exists _in_ the iframe. Your javascript is in there, right? There''s probably another way to get the information from in the iframe on javascript executing in the full window. On Jul 24, 10:15 am, Max Williams <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > we need to pull the iframe into a js function, and from there, grabbing > > the url + the title should be a flip. untested code, but it should be > > something like the below, gathering the iframe''s attributes are <iframe > > name="iframe_name" src="iframe_url"></iframe> > > > top.iframe_name.location.href > > # should give u "iframe_url" and > > > top.iframe_name.document.title > > # should give u the iframe''s <title> > > > hope this helps > > > shai > > Thanks for the advice shai but this just isn''t working for me and i > don''t know why. I installed firebug for firefox, which lists javascript > errors (among other things) and it''s complaining > > "top.myframe has no properties" (myframe is the name of my iframe) > > I must admit i don''t even know how to take this value and do something > with it in rails, so at the minute to test it i''m just doing an alert > box with the returned string. But it seems to be failing while > accessing the myframe object. > > Do you have any idea what the problem might be? Thanks again for > helping by the way. > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> "top.myframe has no properties" (myframe is the name of my iframe) > > I must admit i don''t even know how to take this value and do something > with it in rails, so at the minute to test it i''m just doing an alert > box with the returned string. But it seems to be failing while > accessing the myframe object.if the ''add this page'' button is in the iframe, i believe you can use top.methods etc ... if the button is in the main page, and you want to access the iframe object, you can use: document.frames.myframe # this returns the iframe object i believe you''ll need to adjust the syntax around a little bit for browser compatibility - ie, firefox, safari, and others use slightly different syntaxes, but they all are similar, give or take ... you might have to google around for this if things aren''t working - javascript syntax differences may be one of the problems (if you see there are differences per browser). -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---