需要在弹出窗口中打开Java数组

时间:2014-03-31 18:09:07

标签: javascript php arrays popupwindow

我通过谷歌搜索找到了这个随机图像代码,而我正在尝试做的是,当用户点击时,会弹出一个JavaScript弹出窗口/窗口,而不是从用户那里获取整个控件并发送给网站或文件。我希望有道理吗?

无论如何,这是我的各种文件中的代码:

Header.php(我在本页的整个网站上都有“常见的”JS和PHP调用)。

<script type="text/javascript">
var gallery = new Array();
gallery[0] = new Array(
new Array ("sunbust_sponsors/thumbnails/1.gif", "http://www.stackoverflow.com/"),
new Array ("sunbust_sponsors/thumbnails/2.gif", "#02"),
new Array ("sunbust_sponsors/thumbnails/3.jpg", "#03"),
new Array ("sunbust_sponsors/thumbnails/4.jpg", "#04"));

gallery[1] = new Array(
new Array ("sunbust_sponsors/thumbnails/5.gif", "#05"),
new Array ("sunbust_sponsors/thumbnails/6.jpg", "#06"),
new Array ("sunbust_sponsors/thumbnails/7.png", "#07"),
new Array ("sunbust_sponsors/thumbnails/8.gif", "#08"));

gallery[2] = new Array(
new Array ("sunbust_sponsors/thumbnails/9.jpeg", "#09"),
new Array ("sunbust_sponsors/thumbnails/10.jpg", "#10"),
new Array ("sunbust_sponsors/thumbnails/11.jpg", "#11"),
new Array ("sunbust_sponsors/thumbnails/12.jpg", "#12"),
new Array ("sunbust_sponsors/thumbnails/13.jpg", "#13"));

function pickImageFrom(whichGallery)
{
var idx = Math.floor(Math.random() * gallery[whichGallery].length);

document.write('<a href="' + gallery[whichGallery][idx][1] + '"><img src="/images/' + gallery[whichGallery][idx][0] + '"></a>');
}
</script>

<script type="text/javascript">
function printPage(iFid){
iFid.focus();
iFid.print();
}
</script>

<script type="text/javascript">
function newPopup(url) {
popupWindow = window.open(
url,'popUpWindow','left=200,top=200,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no')
}
</script>

template.php文件,我将这些随机图像称为:

<td width="15" valign="top" class="sponsors" id="sponsors-right">
<table width="100%">
<tr>
<td align="right"><script language="javascript">pickImageFrom(0);</script></td>
</tr>
<tr>
<td align="right">&nbsp;</td>
</tr>
<tr>
<td align="right"><script language="javascript">pickImageFrom(1);</script></td>
</tr>
<tr>
<td align="right">&nbsp;</td>
</tr>
<tr>
<td align="right"><script language="javascript">pickImageFrom(2);</script></td>
</tr>
</table>
</td>
</tr>
</table>

我甚至尝试在header.php文件中使用此行:

document.write('<a href="' + gallery[whichGallery][idx][1] + '"><img src="/images/' + gallery[whichGallery][idx][0] + '"></a>');

将其更改为类似的内容但没有成功:

document.write('<a href="JavaScript:newPopup(' + gallery[whichGallery][idx][1] + ');"><img src="/images/' + gallery[whichGallery][idx][0] + '"></a>');

我认为我正在寻找的东西可以完成,我知道我只是把正确的指针放在错误的位置! :(

提前感谢您的帮助。

祝你有美好的一天!

0 个答案:

没有答案