reactjs - React.js how to return commented video tag for ie9 support -


let's in react want support ie9 wrapping code, example picturefill does:

<picture>   <!--[if ie 9]><video style="display: none;"><![endif]-->   <source srcset="examples/images/extralarge.jpg" media="(min-width: 1000px)">   <source srcset="examples/images/large.jpg" media="(min-width: 800px)">   <!--[if ie 9]></video><![endif]-->   <img srcset="examples/images/medium.jpg" alt="…"> </picture> 

in react, be:

return (                 <picture>                 <!--[if ie 9]><video style="display: none;"><![endif]-->                 <source type="image/webp" classname="full-photo2 slide-init" srcset={"./build/assets/images/photos/responsive/webp/" + image.id + "-400.webp 400w, ./build/assets/images/photos/responsive/webp/" + image.id + "-800.webp 800w, ./build/assets/images/photos/responsive/webp/" + image.id + "-1000.webp 1000w,"} />                 <img classname="full-photo2 slide-init" srcset={"./build/assets/images/photos/responsive/jpg/" + image.id + "-400.jpg 400w, ./build/assets/images/photos/responsive/jpg/" + image.id + "-800.jpg 800w, ./build/assets/images/photos/responsive/jpg/" + image.id + "-1000.jpg 1000w,"} />                 <!--[if ie 9]></video><![endif]-->               </picture>  ) 

of course, react gets angry this.

so how can return ie9 hacks in react returns?

with caveats using dangerouslysetinnerhtml per above link, have made work (using es6):-

const createmarkup = () => {   return  {__html:     `<!--[if ie 9]><video style="display: none;"><![endif]-->     <source srcset="examples/images/extralarge.jpg" media="(min-width: 1000px)">     <source srcset="examples/images/large.jpg" media="(min-width: 800px)">     <!--[if ie 9]></video><![endif]-->     <img src="examples/images/medium.jpg" alt="…">`   }; };  return (   <picture dangerouslysetinnerhtml={createmarkup()}>   </picture> ) 

you can of course pass arguments createmarkup function , interpolate within template string placeholders using ${ } syntax (getting literal es6 template strings):-

const createmarkup = (path) => {   return  {__html:     `<!--[if ie 9]><video style="display: none;"><![endif]-->     <source srcset="${path}extralarge.jpg" media="(min-width: 1000px)">     <source srcset="${path}large.jpg" media="(min-width: 800px)">     <!--[if ie 9]></video><![endif]-->     <img src="${path}medium.jpg" alt="…">`   }; };  return (   <picture dangerouslysetinnerhtml={createmarkup('examples/images/')}>   </picture> ) 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -