zoukankan      html  css  js  c++  java
  • JS 调用打印功能 | 接受页面参数 | 跳出框架(Javascript)

    再来介绍三个 JS 函数,实现的功能依然是很简单的:第一个是使用 JS 调用浏览器的打印功能;第二个用来接受页面 URL 链接上的参数;第三个用来跳出框架。来一看代码为快:

    /**
     * jscript.page package
     * This package contains utility functions that deal with a page as a whole.
     */
    if (typeof jscript == 'undefined') {
      jscript = function() { }
    }
    jscript.page = function() { }
    
    /**
     * This function invokes the browser's print function, if the browser version
     * is high enough.(此函数调用浏览器的打印功能)
     */
    jscript.page.printPage = function() {
    
      if (parseInt(navigator.appVersion) >= 4) {
        window.print();
      }
    
    } // End printPage().
    
    /**
     * This function returns the value of a specified parameter that may have
     * been passed to this page, or it returns an array of all parameters passed
     * to the page, depending on the input parameter.
     *(返回传入页面中的参数)
     * @param  inParamName The name of the parameter to get values for, or null
     *                     to return all parameters.(返回指定名字的参数值,或者全部的参数数组)
     * @return             A string value, the value of the specified parameter,
     *                     or an associative array of all parameters if null
     *                     was passed in.
     */
    jscript.page.getParameter = function(inParamName) {
    
      var retVal = null;
      var varvals = unescape(location.search.substring(1));
      if (varvals) {
        var search_array = varvals.split("&");
        var temp_array = new Array();
        var j = 0;
        var i = 0;
        for (i = 0; i < search_array.length; i++) {
          temp_array = search_array[i].split("=");
          var pName = temp_array[0];
          var pVal = temp_array[1];
          if (inParamName == null) {
            if (retVal == null) {
              retVal = new Array();
            }
            retVal[j] = pName;
            retVal[j + 1] = pVal;
            j = j + 2;
          } else {
            if (pName == inParamName) {
              retVal = pVal;
              break;
            }
          }
        }
      }
      return retVal;
    
    } // End getParameters().
    
    /**
     * Call this function to break out of frames.(跳出框架)
     */
    jscript.page.breakOutOfFrames = function() {
    
      if (self != top) {
        top.location = self.location;
      }
    
    } // End breakOutOfFrames().
    猛击我!!


  • 相关阅读:
    session生命周期
    解决安装sql server 需要重启问题
    myeclipse + tomcat 项目自动部署
    JSP页面转向方式
    关于Response.redirect()方法
    MyEclipse修改项目名称后,部署到tomcat问题
    为Eclipse安装主题插件
    MyEclipse自定义快捷键
    如何查看JSP和Servlet版本
    Wannafly挑战赛2 C.Butterfly(线段树优化枚举)
  • 原文地址:https://www.cnblogs.com/catprayer/p/1861908.html
Copyright © 2011-2022 走看看