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().
    猛击我!!


  • 相关阅读:
    MySQL基础知识-安装MySQL
    java 安装环境 疑问(1)
    java 安装环境
    “64位调试操作花费的时间比预期要长",无法运行调试解决办法
    office完全卸载
    完全卸载oraclean安装
    不能安装64位office提示已安装32位的
    java 之 基础加强(一)
    java 之 dom4j解析xml
    java 之 schema解析
  • 原文地址:https://www.cnblogs.com/catprayer/p/1861908.html
Copyright © 2011-2022 走看看