程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> javascript-關於JSP中鏈接跳轉的問題

javascript-關於JSP中鏈接跳轉的問題

編輯:編程綜合問答
關於JSP中鏈接跳轉的問題

我用javascript寫了一個圖片動態轉換的效果,然後點擊圖片會跳入相應鏈接,如下javascript代碼是我從其他項目代碼移植過來的,結果我發現當點擊進入鏈接頁面的時候會從新打開一個新的頁面,可是我想把初始的頁面轉換成新的頁面,誰懂下列代碼並且知道如何設置的,求指教!

var isIE = (document.all) ? true : false;

var $ = function (id) {
return "string" == typeof id ? document.getElementById(id) : id;
};

var Class = {
create: function() {
return function() { this.initialize.apply(this, arguments); }
}
}

var Extend = function(destination, source) {
for (var property in source) {
destination[property] = source[property];
}
}

var Bind = function(object, fun) {
return function() {
return fun.apply(object, arguments);
}
}

var Each = function(list, fun){
for (var i = 0, len = list.length; i < len; i++) { fun(list[i], i); }
};

//ie only
var RevealTrans = Class.create();
RevealTrans.prototype = {
initialize: function(container, options) {
this._img = document.createElement("img");
this._a = document.createElement("a");

this._timer = null;//計時器
this.Index = 0;//顯示索引
this._onIndex = -1;//當前索引

this.SetOptions(options);

this.Auto = !!this.options.Auto;
this.Pause = Math.abs(this.options.Pause);
this.Duration = Math.abs(this.options.Duration);
this.Transition = parseInt(this.options.Transition);
this.List = this.options.List;
this.onShow = this.options.onShow;

//初始化顯示區域
this._img.style.visibility = "hidden";//第一次變換時不顯示紅x圖
this._img.style.width = this._img.style.height = "100%"; this._img.style.border = 0;
this._img.onmouseover = Bind(this, this.Stop);
this._img.onmouseout = Bind(this, this.Start);
isIE && (this._img.style.filter = "revealTrans()");

this._a.target = "_blank";

$(container).appendChild(this._a).appendChild(this._img);

},
//設置默認屬性
SetOptions: function(options) {
this.options = {//默認值
Auto: true,//是否自動切換
Pause: 1000,//停頓時間(微妙)
Duration: 1,//變換持續時間(秒)
Transition: 7,//變換效果(23為隨機)
List: [],//數據集合,如果這裡不設置可以用Add方法添加
onShow: function(){}//變換時執行
};
Extend(this.options, options || {});
},
Start: function() {
clearTimeout(this._timer);
//如果沒有數據就返回
if(!this.List.length) return;
//修正Index
if(this.Index < 0 || this.Index >= this.List.length){ this.Index = 0; }
//如果當前索引不是顯示索引就設置顯示
if(this._onIndex != this.Index){ this._onIndex = this.Index; this.Show(this.List[this.Index]); }
//如果要自動切換
if(this.Auto){
this._timer = setTimeout(Bind(this, function(){ this.Index++; this.Start(); }), this.Duration * 1000 + this.Pause);
}
},
//顯示
Show: function(list) {
if(isIE){
//設置變換參數
with(this._img.filters.revealTrans){
Transition = this.Transition; Duration = this.Duration; apply(); play();
}
}
this._img.style.visibility = "";
//設置圖片屬性
this._img.src = list.img; this._img.alt = list.text;
//設置鏈接
!!list["url"] ? (this._a.href = list["url"]) : this._a.removeAttribute("href");
//附加函數
this.onShow();
},
//添加變換對象
Add: function(sIimg, sText, sUrl) {
this.List.push({ img: sIimg, text: sText, url: sUrl });
},
//停止
Stop: function() {
clearTimeout(this._timer);
}
};

最佳回答:


this._a.target = "_blank"; 把_blank 改成 _top

_blank 在新窗口中打開被鏈接文檔。
_self 默認。在相同的框架中打開被鏈接文檔。
_parent 在父框架集中打開被鏈接文檔。
_top 在整個窗口中打開被鏈接文檔。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved