一些常用的Js调用类

js

using System;
using System.Web;
using System.Web.UI;

using System;
using System.Web;
using System.Web.UI;

namespace 4ec{
    /// <summary>
    /// 一些常用的Js调用
    /// </summary>
    public class Jscript
    {       
              
        /// <summary>
        /// 弹出JavaScript小窗口
        /// </summary>
        /// <param name="js">窗口信息</param>
        public static void Alert(string message)
        {
            #region
            string js = @"<Script language='JavaScript'>
                    alert('" + message + "');</Script>";
            HttpContext.Current.Response.Write(js);
            #endregion
        }

        /// <summary>
        /// 弹出消息框并且转向到新的URL
        /// </summary>
        /// <param name="message">消息内容</param>
        /// <param name="toURL">连接地址</param>
        public static void AlertAndRedirect(string message, string toURL)
        {
            #region
            string js = "<script language=javascript>alert('{0}');window.location.replace('{1}')</script>";
            HttpContext.Current.Response.Write(string.Format(js, message, toURL));
            #endregion
        }
       
        /// <summary>
        /// 回到历史页面
        /// </summary>
        /// <param name="value">-1/1</param>
        public static void GoHistory(int value)
        {
            #region
            string js = @"<Script language='JavaScript'>
                    history.go({0}); 
                  </Script>";
            HttpContext.Current.Response.Write(string.Format(js, value));
            #endregion
        }

        /// <summary>
        /// 关闭当前窗口
        /// </summary>
        public static void CloseWindow()
        {
            #region
            string js = @"<Script language='JavaScript'>
                    parent.opener=null;window.close(); 
                  </Script>";
            HttpContext.Current.Response.Write(js);
            HttpContext.Current.Response.End();
            #endregion
        }

        /// <summary>
        /// 刷新父窗口
        /// </summary>
        public static void RefreshParent(string url)
        {
            #region
            string js = @"<script>try{top.location=""" +url+@"""}catch(e){location="""+url+@"""}</script>";
            HttpContext.Current.Response.Write(js);
            #endregion
        }

      
        /// <summary>
        /// 刷新打开窗口
        /// </summary>
        public static void RefreshOpener()
        {
            #region
            string js = @"<Script language='JavaScript'>
                    opener.location.reload();
                  </Script>";
            HttpContext.Current.Response.Write(js);
            #endregion
        }

        /// <summary>
        /// 打开指定大小的新窗体
        /// </summary>
        /// <param name="url">地址</param>
        /// <param name="width">宽</param>
        /// <param name="heigth">高</param>
        /// <param name="top">头位置</param>
        /// <param name="left">左位置</param>
        public static void OpenWebFormSize(string url, int width,int heigth,int top,int left)
        {
            #region
            string js = @"<Script language='JavaScript'>window.open('" + url + @"','','height=" + heigth + ",width=" + width + ",top="+top+",left="+left+",location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,titlebar=no,toolbar=no,directories=no');</Script>";

            HttpContext.Current.Response.Write(js);
            #endregion
        }
      
       
        /// <summary>
        /// 转向Url制定的页面
        /// </summary>
        /// <param name="url">连接地址</param>
        public static void JavaScriptLocationHref(string url)
        {
            #region
            string js = @"<Script language='JavaScript'>
                    window.location.replace('{0}');
                  </Script>";
            js = string.Format(js, url);
            HttpContext.Current.Response.Write(js);
            #endregion
        }

        /// <summary>
        /// 打开指定大小位置的模式对话框
        /// </summary>
        /// <param name="webFormUrl">连接地址</param>
        /// <param name="width">宽</param>
        /// <param name="height">高</param>
        /// <param name="top">距离上位置</param>
        /// <param name="left">距离左位置</param>
        public static void ShowModalDialogWindow(string webFormUrl, int width, int height, int top, int left)
        {
            #region
            string features = "dialogWidth:" + width.ToString() + "px"
                + ";dialogHeight:" + height.ToString() + "px"
                + ";dialogLeft:" + left.ToString() + "px"
                + ";dialogTop:" + top.ToString() + "px"
                + ";center:yes;help=no;resizable:no;status:no;scroll=yes";
            ShowModalDialogWindow(webFormUrl, features);
            #endregion
        }

        public static void ShowModalDialogWindow(string webFormUrl, string features)
        {
            string js = ShowModalDialogJavascript(webFormUrl, features);
            HttpContext.Current.Response.Write(js);
        }

        public static string ShowModalDialogJavascript(string webFormUrl, string features)
        {
            #region
            string js = @"<script language=javascript>      
       showModalDialog('" + webFormUrl + "','','" + features + "');</script>";
            return js;
            #endregion
        }
      

    }
}

 

时间: 2024-08-02 07:22:11

一些常用的Js调用类的相关文章

SWFObject Flash js调用类_javascript技巧

 SWFObject是一个基于Javascript的Flash媒体版本检测与嵌入模块,其主要使用目的是让我们将FLASH嵌入网页中的操作更简单,加入了版本检测功能,符合XHTML的标准验证的插入,并解除了IE对FLASH点击激活的限制,对主流浏览器兼容. 首先让我们看一段SWFObject作用的代码: //载入SWFObject类库 <script type="text/javascript" src="swfobject.js" src="swfo

ASP.NET中常用输出JS脚本的类实例_实用技巧

本文实例讲述了ASP.NET中常用输出JS脚本的类,针对过去输出js脚本的类进行了一定的改进.在项目开发中非常具有实用价值.分享给大家供大家参考.具体如下: 很多时候在ASP.NET中我们经常需要输出一些JS脚本,比如弹出一个警告窗口,返回到历史页面等JS功能,我看到网上流传得比较广的是马先光写的一个JScript类,这个类基本将经常用到的JS脚本包含了,非常方便,唯一的不足是作者采用的Response.Write(string msg)的办法,这样造成输出的js脚本在<html></h

代码解释-尽量逐鹿句解释以下代码,js调用action类文件实现的删除功能

问题描述 尽量逐鹿句解释以下代码,js调用action类文件实现的删除功能

浅谈几种常用的JS类定义方法_javascript技巧

// 方法1 对象直接量 var obj1 = { v1 : "", get_v1 : function() { return this.v1; }, set_v1 : function(v) { this.v1 = v; } }; // 方法2 定义函数对象 var Obj = function() { var v1 = ""; this.get_v1 = function() { return this.v1; }; this.set_v1 = function

从Js调用一个AS方法

js 从Js调用一个AS方法: 为了从js调用as的方法,你必须确认一下四个文件都包含在你的html文档中: <script type="text/javascript" src="/path/to/Exception.js"></script>  <script type="text/javascript" src="/path/to/FlashTag.js"></script>

js调用后台、后台调用前台等方法总结_javascript技巧

js调用后台,后台调用前台等方法总结 1. javaScript函数中执行C#代码中的函数: 方法一:1.首先建立一个按钮,在后台将调用或处理的内容写入Button1_Click中; 复制代码 代码如下: protected void Button1_Click(object sender, EventArgs e) { this.TextBox1.Text = "voodooer"; } 2.在前台可以这样调用: 复制代码 代码如下: <input type="but

Google V8编程详解(五)JS调用C++

最近由于忙着解决个人单身的问题,时隔这么久才更新第五章. 上一章主要讲了Google V8的Context概念.那么其实Google V8的基本概念还有FunctionTemplate, ObjectTemplate等比较重要的基本概念,这些概念将在后续章节中进行渗透. 本章主要来讲讲如何通过V8来实现JS调用C++.JS调用C++,分为JS调用C++函数(全局),和调用C++类. JS调用C++函数 JS调用C++函数,就是通过FunctionTemplate和ObjectTemplate进行

js定义类的几种方法(推荐)_javascript技巧

ECMAScript6已经支持了class,但之前版本都不支持类,但是可以通过一些方法来模拟类. js中的类,既是重点,也是难点,很多时候都感觉模棱两可. 首先强调一下js中很重要的3个知识点:this.prototype.constructor. 下面我们来总结一下定义(模拟)类的几种方法: 1.工厂模式 function createObject(name,age){ var obj = new Object(); obj.name = name; obj.age = age; obj.ge

我常用的几个类_php基础

我常用的几个类 修改自hk的 PHP代码:--------------------------------------------------------------------------------/*作用:取得随机字符串参数:    1.(int)$length = 32 #随机字符长度,默认为32    2.(int)$mode = 0 #随机字符类型,0为大小写英文和数字,1为数字,2为小写子木,3为大写字母,4为大小写字母,5为大写字母和数字,6为小写字母和数字返回:取得的字符串使用