jquery - javascript check json for img tag and change src -
hi have custom made crm saves img's in our database /upload/image/image.jpg
have images have full url. need way find out if image starts /upload , add our web address front of image src image shows correctly , not square no image,
we using json , javascript here code have far
function loadnewsstory(e) { if(newsview !== true) { document.getelementbyid("newsarticals").style.display = "block"; document.getelementbyid("activecontent").style.display = "none"; newsview = true; } xmlhttp=new xmlhttprequest(); xmlhttp.open("post","http://media.queerdio.com/mobiledevice/?uri=loadstory/"+e ,false); xmlhttp.send(); var newsreponse = json.parse(xmlhttp.responsetext); var news = newsreponse[0]; document.getelementbyid("newsarticals").innerhtml = '<h1 class="newsheader">' + news.post_title + '</h1> <div class="newsbody">'+news.post_content+'</div>'; window.scrollto(0,0); }
the part need @ news.post_content
great.
edit: added json looks like
"post_content":"<p>dr sharon giese household name in america, starring on hit medical shows dr oz , doctors , making regular appearances on cbs news, cnn , nbc.<\/p>\n<p>dr giese ranked among best in field but, 1 family discovered \"with tragic consequences\" best make mistakes.<\/p>\n<center><img src=\"..\/..\/..\/upload\/health\/dr sharon giese - dr oz - youtube.jpg\" alt=\"dr oz show - dr sharon\" width=\"650\" height=\"488\" \/><\/center>\n<div style=\"padding: 0; margin: -6px 0 4px 10px; text-align: left;\">a screen grab recent appearance on dr oz show. picture: youtube source: youtube<\/div>\n<p>in june 2009, 32-year-old mother-of-two adriana porras underwent liposuction, fat reduction procedure performed dr giese. ms porras died 2 days later of pulmonary embolism.<\/p>\n<p>her husband pablos balzola sued dr giese negligence, claiming did not return frantic calls when ms porras showed signs of severe post-surgery complications, complaining of chest pains , shortness of breath.<\/p>\n<p>in court, pathologists testified had received treatment symptoms, chance of survival have been higher.<\/p>\n<p>it later found out dr giese had not performed procedure in hospital in own home office.<\/p>\n<p>this week reached settlement mr balzola, agreeing pay us$2.3 million (aud$2.5 million)<\/p>\n<p>the money reportedly split between widower, six-year-old daughter maia , nine-year-old son nicholas. mr balzola"
i have used code our feature_images
if(news.featured_image.substring(0, 7) !== "http://") { news.featured_image = "http://www.radiobreakout.com.au/"+news.featured_image; }
but how @ img srcs in post_content.
please consider this:
var articles = document.getelementbyid('newsarticals'); var activecontent = document.getelementbyid('activecontent'); var httpurl = /^http:/; function loadnewsstory(e) { if (newsview !== true) { articles.style.display = 'block'; activecontent.style.display = 'none'; newsview = true; } var xmlhttp = new xmlhttprequest(); xmlhttp.open('post','http://media.queerdio.com/mobiledevice/?uri=loadstory/' + e , false); xmlhttp.send(); // empty articles element first while (articles.children.length) articles.removechild(articles.firstchild); // create document fragment out of response var newsarray = json.parse(xmlhttp.responsetext); var newsel = newsarray.reduce(function htmlcreator(frag, news) { // create elements first var header = document.createelement('h1'); var div = document.createelement('div'); header.classname = 'newsheader'; header.appendchild(document.createtextnode(news.post_title)); // innerhtml shouldn't used, we'll let slide time // next time don't store html in json div.innerhtml = news.post_content; div.classname = 'newsbody'; // loop through of newly added images change sources array.prototype.foreach.call(div.queryselectorall('img'), function sourcemangler(el) { if (!httpurl.test(el.src)) el.src = 'http://www.radiobreakout.com.au/' + el.src.split('/').filter(function removesome(part) { return (part && part !== '..'); }).join('/'); }); frag.appendchild(header); frag.appendchild(div); return frag; }, document.createdocumentfragment()); // append fragment empty element articles.appendchild(newsel); window.scrollto(0,0); }
Comments
Post a Comment