2011-05-21 87 views
-1

我使用html创建页面。但是我面临的问题是我不是在形象塑造。我的代码如下:html页面未在浏览器中显示图像

<html> 
<head runat="server"> 
    <title>Untitled Page</title> 
</head> 
<body style = " background:#FFA500"> 
    <form id="form1" runat="server"> 
    <div> 
    <h1> 
    header_picture 
    </h1> 
    <img src="C:/Documents and Settings/All Users/Documents/My Pictures/Sample Pictures/Water lilies.jpg" /> 

    </div> 
    <div> 
    <h1> 
    here comes the content 
    </h1> 
    </div> 
    <div> 
    <h2> 
    footer_picture 
    </h2> 
    <img src="C:/Documents and Settings/All Users/Documents/My Pictures/Sample Pictures/Blue hills.jpg" /> 
    </div> 
    </form> 
</body> 
</html> 

,但它没有显示我的图片当我运行在浏览器这个HTML文件.. 请帮助我..

is this possible to give image url on run time in <img src> tag in html file.. if yes how can we do that.. 
+0

您需要添加更多信息以获得明确答案。 HTML页面在哪里?你用什么URL来调用它?你是从网络服务器运行这个吗?你在什么浏览器中加载页面? – 2011-05-21 15:06:23

回答

3

您应该将C:/Documents and Settings/All Users/Documents/My Pictures/Sample Pictures/Water lilies.jpg更改为file:///C:/Documents and Settings/All Users/Documents/My Pictures/Sample Pictures/Water lilies.jpg,并且您的其他网址也一样。

+0

好点,这可能也是。 – 2011-05-21 15:06:39

+0

哦,我刚刚看到你发布几乎相同的答案:) – Jamie 2011-05-21 15:08:24

+0

nope,我的是关于别的东西(许多浏览器不允许来自远程URL的file:// URL)。我们可能都是对的 - 没有足够的信息来告诉我 – 2011-05-21 15:09:25

3

从非引用本地文件 - 出于安全原因,在许多现代浏览器中不再可能存在 - file://位置(即使是localhost)。

的Chrome例如将抛出下面的错误在其控制台:

Not allowed to load local resource: file:///C:/path/to/filename 

你将不得不把HTML文件到本地文件夹(这可能不是你想要的,因为你有服务器端代码在其中)或将图像移动到您可以通过Web服务器调用的位置。