2015-03-19 6 views
1

Я тяну новости/спортивные/технические статьи из API и заполняя статьи на своей веб-странице. Проблема здесь в том, что во многих моих статьях я продолжаю получать строку текста, содержащую javascript.Удалить содержимое строки с Javascript

Пример, отрывки из некоторых из наших статей:

Viewers can also choose to ignore the teaser that appears, and it will go away allowing you to watch the video uninterrupted. /* */ if (ads.isMobile()) { (function(window,$){ window.TechCrunch.loader.on('tc_ads_wrapper_omniture', function(){ if (!window.ads.isAdPageSet){ if (typeof window.adSetAdURL == 'function') { window.adSetAdURL('/wp-content/themes/vip/techcrunch-2013/_uac/adpage.html'); window.ads.isAdPageSet = true; } } window.htmlAdWH('348-14-15-135e', "300", "115", 'f', 'adsDivafa83e683e'); }); }(this,this.jQuery)); } /* */ YouTube notes that over time, the plan is to not only help creators provide this enriched experience to viewers, 

другая статья:

Their best strategy, I believe, is to communicate emotions rather than specific nouns and verbs. /* */ if (ads.isMobile()) { (function(window,$){ window.TechCrunch.loader.on('tc_ads_wrapper_omniture', function(){ if (!window.ads.isAdPageSet){ if (typeof window.adSetAdURL == 'function') { window.adSetAdURL('/wp-content/themes/vip/techcrunch-2013/_uac/adpage.html'); window.ads.isAdPageSet = true; } } window.htmlAdWH('348-14-15-135e', "300", "115", 'f', 'adsDiv186350d01b'); }); }(this,this.jQuery)); } /* */ In a classic perceptual psychology experiment, pairs of strangers were asked to communicate emotions through touch alone. The “encoder” was given one of 12 different emotions, then touched the “decoder’s” forearm through a curtain. 

и другое:

“We’re known for digital content advertising, but close to 40% of our business has been mobile commerce for quite some time, in areas like user acquisition and monetization outside of the basic sales transaction.” /* */ if (ads.isMobile()) { (function(window,$){ window.TechCrunch.loader.on('tc_ads_wrapper_omniture', function(){ if (!window.ads.isAdPageSet){ if (typeof window.adSetAdURL == 'function') { window.adSetAdURL('/wp-content/themes/vip/techcrunch-2013/_uac/adpage.html'); window.ads.isAdPageSet = true; } } window.htmlAdWH('348-14-15-135e', "300", "115", 'f', 'adsDivafa83e683e'); }); }(this,this.jQuery)); } /* */ The strategic nature of the investment from Market Tech was part of the reason why Lin said Glispa gave a nod to giving up a stake of the company. 

Есть ли способ, чтобы исключить эти блоки JavaScript который начинается и заканчивается /**/ до t Данные о шляпе заполнены данными. Я просмотрел вызов API, и нет способа удалить его с помощью обратного вызова.

ответ

0

Вы можете использовать регулярное выражение для замены содержимого:

var regpattern = /(\/\*\s\*\/(.*?)\/\*\s\*\/)/gm 

var yourcontent = "include your content here"; 

yourcontent.replace(regpattern,""); 
+0

Спасибо! Попытка выяснить, как подать это на мои «данные», получаемые от обратного вызова –