gpt4 book ai didi

javascript - window.location 在新标签页中打开

转载 作者:行者123 更新时间:2023-11-30 17:08:32 25 4
gpt4 key购买 nike

我希望能够在新选项卡中打开链接,但我不确定要进行哪些更改才能使其正常工作。我在这里看到了关于 window.open 的其他问题,但我在这段代码中没有它可以使用,只有 window.location。我已将唯一实例更改为 window.open,但此时链接不起作用。我认为我可能必须更改链接部分以接受 window.location 但我不确定如何更改。

<head>
<script type='text/javascript'>
function carousel(params){
if(!(params.width>0&&isFinite(params.width)))params.width=100;
if(!(params.height>0&&isFinite(params.height)))params.height=100;
if(!(params.sides>2&&isFinite(params.sides)))params.sides=4;
if(!(params.steps>0&&params.steps<100&&isFinite(params.steps)))params.steps=20;
if(!(params.speed>0&&isFinite(params.speed)))params.speed=8;
if(! (params.image_border_width>=0&&isFinite(params.image_border_width)))params.image_border_width=0;
if(isFinite(params.id)||!params.id)params.id='bad_id_given_'+Math.random();

document.write("<div style='position:relative;overflow:hidden;' id='"+params.id.replace(/[\r\n\t ]+/g,'_')+"'></div>");
var cdiv=document.getElementById(params.id.replace(/[\r\n\t ]+/g,'_'))
cdiv.style.width=params.width+'px';
cdiv.style.height=params.height+'px';
cdiv.style.border=params.border;
cdiv.style.position='relative';
cdiv.style.overflow='hidden';
cdiv.title=params.id;

var counter=0,spinning=true,interval=Math.floor(60000/params.sides/params.steps/params.speed)-5;
interval=isNaN(interval)?200:interval;
var img_position=[],images=[],img_dimension=[];
var img_index=params.images.length+1,img_index_cap=2*params.images.length;
var faces=Math.ceil(params.sides/2), dimension, direction;

function init(){
if(params.direction=="left" || params.direction=="right"){
direction=params.direction;
dimension="width";
}
else if(params.direction=="top" || params.direction=="bottom"){
direction=params.direction;
dimension="height";
}
else {
direction="left";
dimension="width";
}
cdiv.style[dimension]=params[dimension]/(params.size_mode=='image'?Math.sin(Math.PI/params.sides):1)+'px';
var img=new Image();
img.style.position='absolute';
img.style[direction]='10000px';
img.style.width=params.width-2*params.image_border_width+'px';
img.style.height=params.height-2*params.image_border_width+'px';
img.style.border=(params.image_border_width||0)+'px solid '+params.image_border_color;

for(var i=0;i<params.images.length;i++){
images[i]=img.cloneNode(true);
images[i].src=params.images[i];
if(params.links&&params.links[i]&&params.links[i]!=''){
images[i].onclick=new Function("window.location='"+params.links[i]+"'");
images[i].style.cursor=document.all?'hand':'pointer';
}
if(params.titles&&params.titles[i]&&params.titles[i]!='')
images[i].title=params.titles[i];
images[i+params.images.length]=images[i];
if(params.images.length==faces)
images[i+2*params.images.length]=images[i];
cdiv.appendChild(images[i]);
}

var face_size=params.size_mode=='image'?params[dimension]:params[dimension]*Math.sin(Math.PI/params.sides);
var face_offset=params[dimension]*Math.cos(Math.PI/params.sides)/(params.size_mode=='image'?Math.sin(Math.PI/params.sides):1)/2-.5;
var pi_piece=2*Math.PI/params.steps/params.sides;
for(i=0;i<=params.steps*faces;i++){
img_dimension[i]=face_size*Math.sin(pi_piece*i);
img_position[i]=(i<params.steps*params.sides/2)?Math.floor(params[dimension]/2/(params.size_mode=='image'?Math.sin(Math.PI/params.sides):1)-face_offset*Math.cos(pi_piece*i)-img_dimension[i]/2)+'px':'10000px';
img_dimension[i]=img_dimension[i]-2*params.image_border_width>1?Math.ceil(img_dimension[i])-2*params.image_border_width+'px':'1px';
}
}
init();

cdiv.rotate = function(){
setTimeout('document.getElementById("'+cdiv.id+'").rotate()',interval);
if(!spinning) return;
if(++counter>=params.steps){
counter=0;
if(++img_index>=img_index_cap)
img_index=params.images.length;
}
images[img_index-faces].style[direction]='20000px';
for(var i=faces-1;i>=0;i--){
images[img_index-i].style[direction]=img_position[counter+i*params.steps];
images[img_index-i].style[dimension]=img_dimension[counter+i*params.steps];
}
}
cdiv.onmouseover=function(){
spinning=false;
}
cdiv.onmouseout=function(){
spinning=true;
}
setTimeout('document.getElementById("'+cdiv.id+'").rotate()',200);
}
</script>
</head>

然后在正文中:

<script type='text/javascript'>
carousel({id:'YOUR_ID_HERE',
border:'',
size_mode:'image',
width:138,
height:225,
sides:11,
steps:44,
speed:2,
direction:'left',
images:['https://genericlink.com/image1.jpg',
'https://genericlink.com/image2.jpg',
'https://genericlink.com/image3.jpg',
'https://genericlink.com/image4.jpg',
'https://genericlink.com/image5.jpg',
'https://genericlink.com/image6.jpg',
'https://genericlink.com/image7.jpg',
'https://genericlink.com/image8.jpg',
'https://genericlink.com/image9.jpg',
'https://genericlink.com/image10.jpg'],
links: ['https://genericlink.com/page1',
'https://genericlink.com/page2',
'https://genericlink.com/page3',
'https://genericlink.com/page4',
'https://genericlink.com/page5',
'https://genericlink.com/page6',
'https://genericlink.com/page7',
'https://genericlink.com/page8',
'https://genericlink.com/page9',
'https://genericlink.com/page10'],
titles:['1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'10'],
image_border_width:1,
image_border_color:'#ffffff'
});
</script>

最佳答案

您不能将 window.location 替换为 window.open。它的语法略有不同。

http://www.w3schools.com/jsref/met_win_open.asp

尝试替换:

images[i].onclick=new Function("window.location='"+params.links[i]+"'");

与:

images[i].onclick=new Function("window.open("'+params.links[i]+'")");

关于javascript - window.location 在新标签页中打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27492118/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com