(originally posted to jquery group but no ansewr there, so trying here though this isa javascript-library agnostic question. I just know a lot of smart people are here with relavent experience. if this post is considered OT, I apologize) Is there a tool or library that can take HTML and realign the URLs contained within that HTML so that they work properly in a new context? For instance, imagine 1) http://wherever/one/homepage.htm uses Ajax to retrieve HTML from / two/somepage.htm 2) http://wherever/two/somepage.htm has some content like: <a href="http://someplaceelse/abc.htm">ABC</a> <a href="/def.htm">DEF</a> <a href="ghi/page.htm">GHI</a> <a href="jkl.htm">JKL</a> <img src="http://someplaceelse/MNO.gif"> <img src="/PQR/image.gif"> <img src="STU/image.gif"> <img src="VWX.gif"> 3) To drop somepage.htm''s content into the homepage.htm from step 1, the urls must all be refactored to take into account the new location. ABC, DEF, MNO and PQR can be left as they are. GHI, JKL, STU, and VWX must all be modified to take into account the location of the page which was retrieved, or they will be invalid links or unloaded images. It would be handy to drop the content into the element and then get all img and anchor elements and fix them, but it is too late by that time because the browser has already expanded the link or src value. Doing some string search and replacement is feasible but I am wondering what gotchas I could miss, especially with messy or malformed HTML code. Is there anything out there that is built (well) to address this? thanks! Joe --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Walter Lee Davis
2007-Sep-12 13:32 UTC
Re: Refactoring href, src in Ajax retrieved HTML Options
On Sep 12, 2007, at 8:59 AM, joelarson wrote:> 1) http://wherever/one/homepage.htm uses Ajax to retrieve HTML from / > two/somepage.htm > > > 2) http://wherever/two/somepage.htm has some content like: > > > <a href="http://someplaceelse/abc.htm">ABC</a> > <a href="/def.htm">DEF</a> > <a href="ghi/page.htm">GHI</a> > <a href="jkl.htm">JKL</a> > > > <img src="http://someplaceelse/MNO.gif"> > <img src="/PQR/image.gif"> > <img src="STU/image.gif"> > <img src="VWX.gif"> > > > 3) To drop somepage.htm''s content into the homepage.htm from step 1, > the urls must all be refactored to take into account the new > location. ABC, DEF, MNO and PQR can be left as they are. GHI, JKL, > STU, and VWX must all be modified to take into account the location > of > the page which was retrieved, or they will be invalid links or > unloaded images. > > > It would be handy to drop the content into the element and then get > all img and anchor elements and fix them, but it is too late by that > time because the browser has already expanded the link or src value. > > > Doing some string search and replacement is feasible but I am > wondering what gotchas I could miss, especially with messy or > malformed HTML code. > > > Is there anything out there that is built (well) to address this?What about using a base href tag in the enclosing page to auto-expand the references? <base href="http://wherever/" /> Walter --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---