从信息框调用弹出图像库

Calling popup image gallery from infobox?

本文关键字:图像 调用 信息      更新时间:2023-09-26

在我的博客文件夹中,我有两个子文件夹:map和gallery。Map有一个带有餐厅图标的交互式城市地图,gallery为每个餐厅都有一个图像子文件夹。目前,每家餐厅的图像文件夹都包含两个额外的文件:"get_images.php"answers"index.html",前者根据文件夹的内容创建图像数组,后者根据该数组生成图库。我可以从地图上的信息框中调用每个餐厅的弹出图像库,使用:

boxText.innerHTML="<a href='javascript:popUp("+'"../gallery/'+restaurant+'/index.html"'+")'>gallery</a><br/>"

其中"restaurant"变量是从mySql数据库中提取的,"popUp"是创建弹出窗口的函数。

这很麻烦,我想消除在每个餐厅文件夹中都有get_images.php和index.html文件的需要。我可以把get_images.php放在任何地方,并从主脚本中调用它,但我很难找到一种方法来调用位于弹出窗口中的index.html中的rotate_images()函数。功能如下:

var curimg=0
function rotate_images(){
document.getElementById("gallery").setAttribute("src", ""+galleryarray[curimg])
curimg=(curimg<galleryarray.length-1)? curimg+1 : 0
}

我试过

"<a href=   'javascript:rotate_images(" + '"' + '../gallery/pizzahut/files/' + galleryarray[curimg] + '"' + ")'>gallery</a><br/>";

当我把鼠标悬停在链接上时,它显示'javascript:rotate_images("../gallery/pizzahut/files/pizzahut1.jpg")',但当我点击它时什么也没有。我想这是因为我没有包含'img id'标签,但我不知道该把它放在哪里来指示弹出窗口。感谢您的帮助。

例如,将函数rotate_images放入名为map.js的文件中。然后将该文件包含在任何需要该函数的html页面中。

示例:

index.html

<head>
<!-- include map.js here -->
<script src="path/to/map.js"></script>
</head>
<body>
(...)
<a href="#" onclick='javascript:rotate_images(" + '"' + '../gallery/pizzahut/files/' + galleryarray[curimg] + '"' + ");return false'>gallery</a><br/>
(...)
</body>