转义双引号javascript

时间:2012-05-21 15:54:42

标签: javascript

我试图在iphone上观看时运行某种图像格式,否则会尝试使用某些Flash视频

var uagent = navigator.userAgent.toLowerCase();

 if (uagent.search("iphone") > -1){

  document.write("<img src=http://www.demiads.com/images/bc-1300119669-722.gif />");    }
else{   

document.write("<object classid=clsid:d27cdb6e-ae6d-11cf-96b8-444553540000 
codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0 width=728 height=90 id=lang align=middle style=margin-left:3px;>   
 <param name=allowScriptAccess value=sameDomain />      
 <param name=allowFullScreen value=false />         
 <param name=movie value=http://koha.net//repository/reklamat/17_05_12_131575_koha.net_hej_reveal_675x88px.swf /> 
 <param name=quality value=high /> 
 <param name=bgcolor value=#ffffff /> 
 <param name=wmode value=transparent />     
<embed src=http://koha.net//repository/reklamat/17_05_12_131575_koha.net_hej_reveal_675x88px.swf 
quality=high WMODE=transparent bgcolor=#ffffff width=728 height=90 
name=ifm_al align=middle allowScriptAccess=sameDomain 
allowFullScreen=false type=application/x-shockwave-flash 
pluginspage=http://www.macromedia.com/go/getflashplayer /> 
</object>"); 

 }

测试时效果很好,但广告系统不会在发布商网站上显示。我检查了一个网站的源代码,我注意到,无论何时“或”发现都会添加\,从而使其无法正常使用!我试图尽量减少“或”的使用,但这是我尽可能的走。有没有办法解决这个问题?提前谢谢你。

结果

 if (uagent.search(\"iphone\") > -1){

 document.write(\"<img src=http://www.demiads.com/images/bc-1300119669-722.gif />\");    }
 else{   

   document.write(\"<object classid=clsid:d27cdb6e-ae6d-11cf-96b8-444553540000 
   codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0      width=728 height=90 id=lang align=middle style=margin-left:3px;>   
   <param name=allowScriptAccess value=sameDomain />      
   <param name=allowFullScreen value=false />         
   <param name=movie value=http://koha.net//repository/reklamat/17_05_12_131575_koha.net_hej_reveal_675x88px.swf /> 
   <param name=quality value=high /> 
   <param name=bgcolor value=#ffffff /> 
   <param name=wmode value=transparent />     
   <embed src=http://koha.net//repository/reklamat/17_05_12_131575_koha.net_hej_reveal_675x88px.swf 
   quality=high WMODE=transparent bgcolor=#ffffff width=728 height=90 
   name=ifm_al align=middle allowScriptAccess=sameDomain 
   allowFullScreen=false type=application/x-shockwave-flash 
   pluginspage=http://www.macromedia.com/go/getflashplayer /> 
   </object>\"); 

     }

1 个答案:

答案 0 :(得分:0)

为什么""缺少这些属性?你知道你可以使用单引号,如:

document.write('<img src="bc-1300119669-722.gif" />');