如何在javascript中重定向到同一窗口中的其他页面
我正在创建一个应用程序,其中我正在使用图像转换幻灯片。在图像幻灯片中,我使用超链接转到另一个页面。但页面在新窗口中打开。我想在同一个窗口中打开页面如何在javascript中重定向到同一窗口中的其他页面,javascript,Javascript,我正在创建一个应用程序,其中我正在使用图像转换幻灯片。在图像幻灯片中,我使用超链接转到另一个页面。但页面在新窗口中打开。我想在同一个窗口中打开页面 flashyslideshow.prototype.getSlideHTML=function (index) { var slideHTML= (this.imagearray[index][1])?'<a href= "' + this.imagearray[index][1]+'" target = "'+this.imagea
flashyslideshow.prototype.getSlideHTML=function (index) {
var slideHTML= (this.imagearray[index][1])?'<a href= "' + this.imagearray[index][1]+'" target = "'+this.imagearray[index][2]+ "_self" '">\n' : ''; //hyperlink slide?
slideHTML+='<img src="'+this.imagearray[index][0]+'" height="550" width="100%" >';
slideHTML+=(this.imagearray[index][1])? '</a><br />' : '<br />';
slideHTML+=(this.imagearray[index][3])? '<font face="bookman old style" color="blue" size="3">' + this.imagearray[index][3] : ''; //text description?
return slideHTML; //return HTML for the slide at the specified index
}
<a href="www.google.com" target="_self">Google</a>
flashyslideshow.prototype.getSlideHTML=函数(索引){
var slideHTML=(this.imagearray[index][1])?“
”:“
”;
slideHTML+=(this.imagearray[index][3])?“”+this.imagearray[index][3]:“”;//文本描述?
return slideHTML;//返回指定索引处幻灯片的HTML
}
在您的
标签内,添加
target="_self"
这将强制链接在同一窗口中打开。
flashyslideshow.prototype.getSlideHTML=function (index) {
var slideHTML= (this.imagearray[index][1])?'<a href= "' + this.imagearray[index][1]+'" target = "'+this.imagearray[index][2]+ "_self" '">\n' : ''; //hyperlink slide?
slideHTML+='<img src="'+this.imagearray[index][0]+'" height="550" width="100%" >';
slideHTML+=(this.imagearray[index][1])? '</a><br />' : '<br />';
slideHTML+=(this.imagearray[index][3])? '<font face="bookman old style" color="blue" size="3">' + this.imagearray[index][3] : ''; //text description?
return slideHTML; //return HTML for the slide at the specified index
}
<a href="www.google.com" target="_self">Google</a>
您可以通过确保目标为空来实现这一点,类似这样
<form id="form" method="post" action="index.html">
避免使用target
属性,它将在同一窗口中加载检查:target=“”+this.imagearray[index][2]+“\u self”,这不正确。你为什么不干脆用target=''你自己(或者什么都不做)?这正是反对的案例之一。人们似乎讨厌if语句,并尽可能避免它们,但是在这种情况下,它会使代码看起来不那么凌乱