Why split the [removed] tag when writing it with [removed]()?

前端 未结 5 1165
挽巷
挽巷 2020-11-21 07:37

Why do some sites (or advertisers that give clients javascript code) employ a technique of splitting the tags

5条回答
  •  悲&欢浪女
    2020-11-21 07:54

    The inside the Javascript string litteral is interpreted by the HTML parser as a closing tag, causing unexpected behaviour (see example on JSFiddle).

    To avoid this, you can place your javascript between comments (this style of coding was common practice, back when Javascript was poorly supported among browsers). This would work (see example in JSFiddle):

    
    

    ...but to be honest, using document.write is not something I would consider best practice. Why not manipulating the DOM directly?

    
    

提交回复
热议问题