PDA

View Full Version : need help for Link open in a BLANK window



gill_bin
08-12-2010, 12:43 PM
Hi folks
I have a below JavaScript & I want to know when user click on image,
Link will open in a BLANK window, right now link open in a same window.
Thanks


var ShowCount = 12;
var i;
var str="";
var sImg = new Array();
var sWord = new Array();
var sLink = new Array();

sImg[0]="images/20070808151110c56a3.jpg";
sWord[0]="zoom view";
sLink[0]="http://www.google.com/";

sImg[1]="images/20070808143928b74c3.jpg";
sWord[1]="zoom view";
sLink[1]="http://www.google.com/";

sImg[2]="images/200708081400391b3bd.jpg";
sWord[2]="zoom view";
sLink[2]="http://www.google.com/";

sImg[3]="images/200708081107160c9d0.jpg";
sWord[3]="zoom view";
sLink[3]="http://www.google.com/";

sImg[4]="images/20070808104024c029b.jpg";
sWord[4]="zoom view";
sLink[5]="http://www.google.com/";

sImg[5]="images/200708081042015a236.jpg";
sWord[5]="zoom view";
sLink[5]="http://www.google.com/";

sImg[6]="images/20070808081842a9f33.jpg";
sWord[6]="zoom view";
sLink[6]="http://www.google.com/";

sImg[7]="images/20070807160434e9217.jpg";
sWord[7]="zoom view";
sLink[7]="http://www.google.com/";

sImg[8]="images/20070807093857a48be.jpg";
sWord[8]="zoom view";
sLink[8]="http://www.google.com/";

sImg[9]="images/2007080716440308de8.jpg";
sWord[9]="zoom view";
sLink[9]="http://www.google.com/";


sImg[10]="images/20070807111517977a0.jpg";
sWord[10]="zoom view";
sLink[10]="http://www.google.com/";

sImg[11]="images/2007080710170873350.jpg";
sWord[11]="zoom view";
sLink[11]="http://www.google.com/";

sImg[12]="images/2007080710380313ed9.jpg";
sWord[12]="zoom view";
sLink[12]="http://www.google.com/";


function mixArray(source)
{
//var source=[1,2,3,4,5];
var goal=[];
for(var i=0;i<source.length;i++)
{
var pos=Math.floor(Math.random()*(source.length-i));
goal[i]=source[pos];
source[pos]=source[source.length-1-i];
}
return goal;
}

var Ro = new Array();
for (var x=0;x<sImg.length ;x++ )
{
Ro[x]=x;
}
Ro=mixArray(Ro);


for (var j=0;j<ShowCount ; j++)
{

str += "<li><a href='" + sLink[Ro[j]] + "'><img src='" + sImg[Ro[j]] + "' /><span>" + sWord[Ro[j]] + "</span></a></li>";
}
str="<ul>" + str + "</ul>";
document.getElementById("newsImg").innerHTML=str;

http://i37.tinypic.com/30sdrls.jpg

Beverleyh
08-12-2010, 01:40 PM
Try changing this line


str += "<li><a href='" + sLink[Ro[j]] + "'><img src='" + sImg[Ro[j]] + "' /><span>" + sWord[Ro[j]] + "</span></a></li>";

to this;


str += "<li><a href='" + sLink[Ro[j]] + "' target="_blank"><img src='" + sImg[Ro[j]] + "' /><span>" + sWord[Ro[j]] + "</span></a></li>";

gill_bin
08-12-2010, 01:57 PM
it's not working. Please see screen shot.

Thanks in advance.
http://i38.tinypic.com/swy99i.jpg

bluewalrus
08-12-2010, 02:04 PM
escape the quotes in the target or use single quotes

target=\"_blank\"

or

target='_blank'

jscheuer1
08-12-2010, 02:05 PM
That should be:


str += "<li><a href='" + sLink[Ro[j]] + "' target='_blank'><img src='" + sImg[Ro[j]] + "' /><span>" + sWord[Ro[j]] + "</span></a></li>";

Single quotes were being used inside the string as the literal quotes, so this must remain consistent.

gill_bin
08-13-2010, 02:56 AM
Working fine.

Thanks Dear.