我从API中提取新闻/体育/科技文章,并在我的网页中填充文章。这里的问题是,在我的很多文章中,我不断收到一串包含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块。我调查了API调用,无法通过回调实际删除它。
答案 0 :(得分:0)
您可以使用正则表达式替换内容:
var regpattern = /(\/\*\s\*\/(.*?)\/\*\s\*\/)/gm
var yourcontent = "include your content here";
yourcontent.replace(regpattern,"");