subWin=newArray(0,10);
vari = 0;
for(i;i<4;i++){
alert("In loop, OP window!="+i);
subWin[i]=window.open("tmp.txt", 'sample"+i', "newwindow");
alert("Get>="+subWin[i].name+"=="+"XX"+i);
};
This second, alert, second, argument, >"sample"+i<< appears like this. The same goes for single quotes.
I'd like to write that the behavior is changed to sanpl1,sampl2,,,,
Is there any way to write it? I look forward to your kind cooperation.
javascript
A single-quote, double-quote string literal does nothing but interpret the escape with a backslash.You cannot write variables, so the value of the string literal '"sample"+i'
is "sample"+i
.
In this case, simply remove the outer single quote and it should be as expected.window.open("tmp.txt", "sample" + i, ...
You can also use template strings.In this case, you can use variables in the string.Enclose the string in the backquote and enclose the expression you want to evaluate with ${~}
.
window.open("tmp.txt", `sample${i}`, ...
© 2024 OneMinuteCode. All rights reserved.