您的位置:首页 > Web前端 > JavaScript

JS 调用打印功能 | 接受页面参数 | 跳出框架(Javascript)

2010-10-26 21:05 861 查看
再来介绍三个 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().


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().
猛击我!!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: