【问题标题】:view image on new window在新窗口中查看图像
【发布时间】:2016-11-17 23:47:41
【问题描述】:

我使用 php 编写了代码,它将在浏览器中显示来自指定路径的所有图像,并定义了宽度和高度。现在我想开发一个代码,如果我单击任何图像,它应该在新窗口中以原始大小显示我。请指导。不知道怎么弄。

已编辑的问题

image.php

<script language="javascript"> //disabling right click
document.onmousedown=disableclick;
status="Right Click Disabled";
function disableclick(event)
{
    if(event.button==2)
    {
        alert(status);
        return false;    
    }
}
</script>

<?php //displaying images on browser
$dir= '../images/';


$file_display = array('jpg','jpeg','png','gif');
if (file_exists($dir) == false) 
{
    echo 'Directory \''. $dir. '\' not found!';
}
else 
{
    $dir_contents = scandir($dir);

    foreach ($dir_contents as $file) 
    {
        $tmp = explode('.', $file);

        $f_e = end($tmp);
        $file_type = strtolower($f_e);

        if ($file !== '.' && $file !== '..' && in_array($file_type, $file_display) == true) 
        {
            echo '<img src="'. $dir.$file. '" alt="'.$file. '"style="width:250px;height:250px" />';
        }
    } 
}
?>

此代码将在浏览器中显示所有图像,如果我单击任何应在新窗口中显示图像的图像,则在浏览器中。

如何获取点击图片的图片id?

【问题讨论】:

  • 你试过window.open吗?
  • 在 window.open 中写什么。我的意思是在浏览器中它向我显示所有图像然后我如何获取它们的图像名称然后将其发送到另一个页面。
  • 不清楚你想要什么。向我们展示你到目前为止所拥有的......也许这会让你想要什么。展示您如何在页面上加载图片。
  • 好的,我正在编辑我的问题
  • 使用src属性打开图片。像这样echo '&lt;img onclick="window.open(this.src);" src="'. $dir.$file. '" alt="'.$file. '"style="width:250px;height:250px" /&gt;'; 或分配一个类名并为其编写事件函数。

标签: javascript php


【解决方案1】:

试试这个:

<a href="#" target="_blank"><img src="IMG URL" ></a>

【讨论】:

    【解决方案2】:

    你有“目标”属性,你可以这样使用它:

    <a href=url to your picture target="_blank">Image in new window</a>
    

    target = "_blank" 将在新窗口中打开 url,尝试根据需要调整它。

    你也可以把你的图片放在'a'属性的顶部作为“图片链接”

    【讨论】:

    • “点击”事件发生后,处理函数获取'e'作为参数,
    【解决方案3】:

    echo '&lt;a href="'. $dir.$file. '" target="_blank" title="'.$file. '"&gt;&lt;img src="'. $dir.$file. '" alt="'.$file. '" style="width: 250px;height: 250px"&gt;&lt;/a&gt;';

    只需用“定位”新窗口/标签的链接将 img 括起来。

    如果您知道图片存储在服务器上的 url 并且知道该位置的 url,您可以在链接中指定:

    例如:&lt;a href="/images/'. $file. '" target="_blank" title="'.$file. '"&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多