js代码动态生成代码(此为一张页面的后端cs代码)
2010-06-10 08:11
561 查看
using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.IO; using System.Text; public partial class Examples_CreatJs_demo : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { CreateJsFile("tt",800,300,0); } } protected void CreateJsFile(string jsFileName, int width, int height, int adType) { string jsDirctory = Server.MapPath("~") + "/Examples/CreatJs/newJs"; string jsPath = Server.MapPath("~") + "/Examples/CreatJs/newJs/" + jsFileName + ".js"; StringBuilder sb = new StringBuilder(); if (Directory.Exists(jsDirctory)) { try { Directory.CreateDirectory(jsDirctory); } catch(Exception msg) { throw new Exception(msg.ToString()); } } if (File.Exists(jsPath)) { try { File.Delete(jsPath); } catch(Exception msg) { throw new Exception(msg.ToString()); } } sb = GetJs(adType,width,height); if (sb == null) { Response.Write("<mce:script language='javascript'><!-- alert('没有此广告类别或没有对此广告类别进行处理!') // --></mce:script>"); return; } try { File.AppendAllText(jsPath, sb.ToString()); //StreamWriter sw = new StreamWriter(jsPath, false, System.Text.Encoding.UTF8); //根据路径生成文件 } catch (Exception msg) { throw new Exception(msg.ToString()); } } protected StringBuilder GetJs(int adType,int width,int height) { StringBuilder sb = new StringBuilder(); switch (adType) { case 0: sb = BigSlidePhoto(width, height); break; default: return null; } return sb; } /// <summary> /// 大幻灯片广告 /// </summary> protected StringBuilder BigSlidePhoto(int width, int height) { StringBuilder sb = new StringBuilder(); //s += "document.writeln(/"<link type='text/css' rel='stylesheet' href="galleryview.css" mce_href="galleryview.css" />/")/n"; //s += "document.writeln(/"<mce:script type='text/javascript' src="js/jquery-1.4.min.js" mce_src="js/jquery-1.4.min.js"></mce:script>/")/n"; //s += "document.writeln(/"<mce:script type='text/javascript' src="js/jquery.easing.1.3.js" mce_src="js/jquery.easing.1.3.js"></mce:script>/")/n"; //s += "document.writeln(/"<mce:script type='text/javascript' src="js/jquery.galleryview-1.1.js" mce_src="js/jquery.galleryview-1.1.js"></mce:script>/")/n"; //s += "document.writeln(/"<mce:script type='text/javascript' src="js/jquery.timers-1.1.2.js" mce_src="js/jquery.timers-1.1.2.js"></mce:script>/")/n"; sb.Append("document.writeln(/"<div id='photos' class='galleryview'>/")/n"); sb.Append("document.writeln(/" <div class='panel'>/")/n"); sb.Append("document.writeln(/" <img src="img/01.jpg" mce_src="img/01.jpg" /> /")/n"); sb.Append("document.writeln(/" <div class='panel-overlay'>/")/n"); sb.Append("document.writeln(/" <h2>Effet du soleil sur le paysage</h2>/")/n"); sb.Append("document.writeln(/" <p>Photo by <a href="http://www.sxc.hu/profile/tomharry" mce_href="http://www.sxc.hu/profile/tomharry" target='_blank'>tomharry</a>. View full-size photo <a href="http://www.sxc.hu/photo/158829" mce_href="http://www.sxc.hu/photo/158829" target='_blank'>here</a>.</p>/")/n"); sb.Append("document.writeln(/" </div>/")/n"); sb.Append("document.writeln(/" </div>/")/n"); sb.Append("document.writeln(/" <div class='panel'>/")/n"); sb.Append("document.writeln(/" <img src="img/02.jpg" mce_src="img/02.jpg" /> /")/n"); sb.Append("document.writeln(/" <div class='panel-overlay'>/")/n"); sb.Append("document.writeln(/" <h2>Eden</h2>/")/n"); sb.Append("document.writeln(/" <p>Photo by <a href="http://www.sxc.hu/profile/emsago" mce_href="http://www.sxc.hu/profile/emsago" target='_blank'>emsago</a>. View full-size photo <a href="http://www.sxc.hu/photo/152865" mce_href="http://www.sxc.hu/photo/152865" target='_blank'>here</a>.</p>/")/n"); sb.Append("document.writeln(/" </div>/")/n"); sb.Append("document.writeln(/" </div>/")/n"); sb.Append("document.writeln(/" <div class='panel'>/")/n"); sb.Append("document.writeln(/" <img src="img/03.jpg" mce_src="img/03.jpg" /> /")/n"); sb.Append("document.writeln(/" <div class='panel-overlay'>/")/n"); sb.Append("document.writeln(/" <h2>Snail on the Corn</h2>/")/n"); sb.Append("document.writeln(/" <p>Photo by <a href="http://www.sxc.hu/profile/baines" mce_href="http://www.sxc.hu/profile/baines" target='_blank'>baines</a>. View full-size photo <a href="http://www.sxc.hu/photo/34453" mce_href="http://www.sxc.hu/photo/34453" target='_blank'>here</a>.</p>/")/n"); sb.Append("document.writeln(/" </div>/")/n"); sb.Append("document.writeln(/" </div>/")/n"); sb.Append("document.writeln(/" <div class='panel'>/")/n"); sb.Append("document.writeln(/" <img src="img/04.jpg" mce_src="img/04.jpg" /> /")/n"); sb.Append("document.writeln(/" <div class='panel-overlay'>/")/n"); sb.Append("document.writeln(/" <h2>Flowers</h2>/")/n"); sb.Append("document.writeln(/" <p>Photo by <a href="http://www.sxc.hu/profile/jazza" mce_href="http://www.sxc.hu/profile/jazza" target='_blank'>jazza</a>. View full-size photo <a href="http://www.sxc.hu/photo/990169" mce_href="http://www.sxc.hu/photo/990169" target='_blank'>here</a>.</p>/")/n"); sb.Append("document.writeln(/" </div>/")/n"); sb.Append("document.writeln(/" </div>/")/n"); sb.Append("document.writeln(/" <div class='panel'>/")/n"); sb.Append("document.writeln(/" <img src="img/06.jpg" mce_src="img/06.jpg" /> /")/n"); sb.Append("document.writeln(/" <div class='panel-overlay'>/")/n"); sb.Append("document.writeln(/" <h2>Alone Beach 2B</h2>/")/n"); sb.Append("document.writeln(/" <p>Photo by <a href="http://www.sxc.hu/profile/sgursozlu" mce_href="http://www.sxc.hu/profile/sgursozlu" target='_blank'>sgursozlu</a>. View full-size photo <a href="http://www.sxc.hu/photo/738279" mce_href="http://www.sxc.hu/photo/738279" target='_blank'>here</a>.</p>/")/n"); sb.Append("document.writeln(/" </div>/")/n"); sb.Append("document.writeln(/" </div>/")/n"); sb.Append("document.writeln(/" <div class='panel'>/")/n"); sb.Append("document.writeln(/" <img src="img/05.jpg" mce_src="img/05.jpg" /> /")/n"); sb.Append("document.writeln(/" <div class='panel-overlay'>/")/n"); sb.Append("document.writeln(/" <h2>Sunrise Trees</h2>/")/n"); sb.Append("document.writeln(/" <p>Photo by <a href="http://www.sxc.hu/profile/a_glitch" mce_href="http://www.sxc.hu/profile/a_glitch" target='_blank'>a_glitch</a>. View full-size photo <a href="http://www.sxc.hu/photo/289581" mce_href="http://www.sxc.hu/photo/289581" target='_blank'>here</a>.</p>/")/n"); sb.Append("document.writeln(/" </div>/")/n"); sb.Append("document.writeln(/" </div>/")/n"); sb.Append("document.writeln(/" <div class='panel'>/")/n"); sb.Append("document.writeln(/" <img src="img/07.jpg" mce_src="img/07.jpg" /> /")/n"); sb.Append("document.writeln(/" <div class='panel-overlay'>/")/n"); sb.Append("document.writeln(/" <h2>Waterfall</h2>/")/n"); sb.Append("document.writeln(/" <p>Photo by <a href="http://www.sxc.hu/profile/thesaint" mce_href="http://www.sxc.hu/profile/thesaint" target='_blank'>thesaint</a>. View full-size photo <a href="http://www.sxc.hu/photo/174331" mce_href="http://www.sxc.hu/photo/174331" target='_blank'>here</a>.</p>/")/n"); sb.Append("document.writeln(/" </div>/")/n"); sb.Append("document.writeln(/" </div>/")/n"); sb.Append("document.writeln(/" <div class='panel'>/")/n"); sb.Append("document.writeln(/" <img src="img/08.jpg" mce_src="img/08.jpg" /> /")/n"); sb.Append("document.writeln(/" <div class='panel-overlay'>/")/n"); sb.Append("document.writeln(/" <h2>Death Valley</h2>/")/n"); sb.Append("document.writeln(/" <p>Photo by <a href="http://www.sxc.hu/profile/djkmart" mce_href="http://www.sxc.hu/profile/djkmart" target='_blank'>djkmart</a>. View full-size photo <a href="http://www.sxc.hu/photo/270109" mce_href="http://www.sxc.hu/photo/270109" target='_blank'>here</a>.</p>/")/n"); sb.Append("document.writeln(/" </div>/")/n"); sb.Append("document.writeln(/" </div>/")/n"); sb.Append("document.writeln(/" <ul class='filmstrip'>/")/n"); sb.Append("document.writeln(/" <li><img src="img/frame-01.jpg" mce_src="img/frame-01.jpg" alt='Effet du soleil' title='Effet du soleil' /></li>/")/n"); sb.Append("document.writeln(/" <li><img src="img/frame-02.jpg" mce_src="img/frame-02.jpg" alt='Eden' title='Eden' /></li>/")/n"); sb.Append("document.writeln(/" <li><img src="img/frame-03.jpg" mce_src="img/frame-03.jpg" alt='Snail on the Corn' title='Snail on the Corn' /></li>/")/n"); sb.Append("document.writeln(/" <li><img src="img/frame-04.jpg" mce_src="img/frame-04.jpg" alt='Flowers' title='Flowers' /></li>/")/n"); sb.Append("document.writeln(/" <li><img src="img/frame-06.jpg" mce_src="img/frame-06.jpg" alt='Alone Beach' title='Alone Beach' /></li>/")/n"); sb.Append("document.writeln(/" <li><img src="img/frame-05.jpg" mce_src="img/frame-05.jpg" alt='Sunrise Trees' title='Sunrise Trees' /></li>/")/n"); sb.Append("document.writeln(/" <li><img src="img/frame-07.jpg" mce_src="img/frame-07.jpg" alt='Waterfall' title='Waterfall' /></li>/")/n"); sb.Append("document.writeln(/" <li><img src="img/frame-08.jpg" mce_src="img/frame-08.jpg" alt='Death Valley' title='Death Valley' /></li>/")/n"); sb.Append("document.writeln(/" </ul>/")/n"); sb.Append("document.writeln(/"</div>/")/n"); sb.Append("document.writeln(/"<mce:script type='text/javascript'><!-- /")/n"); sb.Append("document.writeln(/" $(document).ready(function(){/")/n"); sb.Append("document.writeln(/" $(/'#photos/').galleryView({/")/n"); sb.Append("document.writeln(/" panel_width: " + width + ",/")/n"); sb.Append("document.writeln(/" panel_height: " + height + ",/")/n"); sb.Append("document.writeln(/" frame_width: 100,/")/n"); sb.Append("document.writeln(/" frame_height: 100/")/n"); sb.Append("document.writeln(/" });/")/n"); sb.Append("document.writeln(/" });/")/n"); sb.Append("document.writeln(/" // --></mce:script>/")/n"); //sw.Write(s); //sw.Flush(); //sw.Close(); return sb; } protected void Button1_Click(object sender, EventArgs e) { int width = int.Parse(TextBox1.Text.ToString()); int height = int.Parse(TextBox2.Text.ToString()); CreateJsFile("tt", width, height, 0); } }
相关文章推荐
- js代码文件动态生成(此为一张页面的后端cs代码)
- 动态生成页面元素的代码
- jsp页面的动态目录树生成代码
- PHP 动态生成静态HTML页面示例代码
- 关于jeecg自动生成代码后,进入前端页面后后端报错的问题
- PHP 动态生成静态HTML页面示例代码
- 动态生成适用于像sql的where条件拼接的面板js代码 与 php处理代码 (一)
- asp.net2.0中通过CS代码来动态的指定aspx页面中head中的信息
- asp.net2.0中通过CS代码来动态的指定aspx页面中head中的信息
- 动态生成适用于像sql的where条件拼接的面板js代码 与 php处理代码 (二)
- [Win8]Windows8开发笔记(三):代码读取图片动态生成页面
- 写一个静态HTML页面,直接写HTML代码和用JS动态生成代码,哪种方式要好
- 动态生成页面元素的代码
- asp.net2.0中通过CS代码来动态的指定aspx页面中head中的信息
- 如何将asp.net的后台cs代码移动到页面上
- SolpartMenu的使用:(二)、在ASP.NET页面中使用SolpartMenu控件之动态的加载数据库中的数据来生成菜单
- 动态生成JAVA代码
- Java下的框架编程(反射,泛型,元数据,CGLib,代码动态生成,AOP,动态语言嵌入)
- 动态页面生成静态页面的原理
- 怎样在前页面显示cs后台代码中的字符串变量