2011-05-21 84 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服務器調用的位置。