单击按钮时无法预览 js 嵌入代码

发布于 2024-12-10 17:52:58 字数 1820 浏览 0 评论 0原文

我要求用户将js(以及任何)嵌入代码放入textarea中,例如以下js嵌入代码提交到textarea中,

<script type='text/javascript' src='http://video.boston.cbslocal.com/global/video/videoplayer.js?rnd=275172;hostDomain=video.boston.cbslocal.com;playerWidth=320;playerHeight=240;isShowIcon=true;clipId=6326565;flvUri=;partnerclipid=;adTag=News;advertisingZone=CBS.BOSTON%252Fworldnowplayer;enableAds=true;landingPage=;islandingPageoverride=false;playerType=STANDARD_EMBEDDEDscript;controlsType=fixed'></script>

textarea旁边有一个预览按钮,单击该按钮我可以获得文本区域的内容并将其分配给隐藏div 'id_bm_embed_view_div' 并稍后显示此 div,如:

$('#id_bm_embed_view_div').html(textarea contet);
$('#id_bm_embed_view_div').show();

twitter 和 youtube 嵌入代码似乎工作正常,显示正确的预览,但我不适合 js 嵌入代码,我在这里缺少什么?

例如,如果我输入以下嵌入代码,我将获得嵌入代码的正确预览

<!-- Generated by EmbeVi (http://www.embevi.com) -->  <object  classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" type="application/x-shockwave-flash" width="425" height="344">  <param name="movie" value="http://www.youtube.com/v/R4j8p6zlFHs&f=videos&app=youtube_gdata" /><param name="wmode" value="transparent" /><param name="allowScriptAccess" value="always" /><param name="pluginspage" value="http://get.adobe.com/flashplayer/" />  <embed  type="application/x-shockwave-flash" src="http://www.youtube.com/v/R4j8p6zlFHs&f=videos&app=youtube_gdata" width="425" height="344" wmode="transparent" allowScriptAccess="always" pluginspage="http://get.adobe.com/flashplayer/" flashvars="" quality="high" allowfullscreen="true" loop="false" autoplay="false" autostart="false" scale="exactfit" align="middle" /> </object>

I am asking user to put js (well any) embed code into a textarea e.g. the following js embed code is submitted into textarea

<script type='text/javascript' src='http://video.boston.cbslocal.com/global/video/videoplayer.js?rnd=275172;hostDomain=video.boston.cbslocal.com;playerWidth=320;playerHeight=240;isShowIcon=true;clipId=6326565;flvUri=;partnerclipid=;adTag=News;advertisingZone=CBS.BOSTON%252Fworldnowplayer;enableAds=true;landingPage=;islandingPageoverride=false;playerType=STANDARD_EMBEDDEDscript;controlsType=fixed'></script>

there is preview button next to textarea on click of which I get the contents of the text area and assign it to hidden div 'id_bm_embed_view_div' and later showing this div like:

$('#id_bm_embed_view_div').html(textarea contet);
$('#id_bm_embed_view_div').show();

twitter and youtube embed code seems works fine, shows proper preview, but I don't get it right for js embed code, what I am missing here?

e.g. if I put following embed code I get the proper preview of the embed code

<!-- Generated by EmbeVi (http://www.embevi.com) -->  <object  classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" type="application/x-shockwave-flash" width="425" height="344">  <param name="movie" value="http://www.youtube.com/v/R4j8p6zlFHs&f=videos&app=youtube_gdata" /><param name="wmode" value="transparent" /><param name="allowScriptAccess" value="always" /><param name="pluginspage" value="http://get.adobe.com/flashplayer/" />  <embed  type="application/x-shockwave-flash" src="http://www.youtube.com/v/R4j8p6zlFHs&f=videos&app=youtube_gdata" width="425" height="344" wmode="transparent" allowScriptAccess="always" pluginspage="http://get.adobe.com/flashplayer/" flashvars="" quality="high" allowfullscreen="true" loop="false" autoplay="false" autostart="false" scale="exactfit" align="middle" /> </object>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

§对你不离不弃 2024-12-17 17:52:58

我认为您应该对提交的数据中的任何 / 进行转义。
我尝试了这些例子:

$("div").html("<script type='text/javascript'>alert('hi');</script>");
// Simply put raw data in div

这不起作用。它在 div 中打印 ");
但这是有效的:

$("div").html("<script type='text/javascript'>alert('hi');<\/script>");
// Note: <\/script>

希望有帮助。

I think you should scape any / in your submitted data.
I tried these examples:

$("div").html("<script type='text/javascript'>alert('hi');</script>");
// Simply put raw data in div

This doesn't work. It prints "); in div.
But this works:

$("div").html("<script type='text/javascript'>alert('hi');<\/script>");
// Note: <\/script>

Hope it helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文