2010-10-09 69 views
3

我們在使用html標記時遇到了一個奇怪的行爲。其實這個問題是因爲標籤使用不當引起的。因此,該頁面在Mozilla Firefox中提交了3次,在IE7中提交了2次。這是問題。HTML鏈接標記的奇怪行爲

<link rel="stylesheet" type="text/css" title="Style" href=''/css/image.css'> 

這是我們在我們的J2EE應用程序中使用的代碼。當我們檢查請求和響應時(使用HTTP Watch),我們發現該頁面從服務器請求了3次。我們發現在href=之後引起此問題的附加「報價」。我們無法找出導致多頁提交的原因。是否因爲額外的報價使得href爲空,並且因爲該瀏覽器試圖從加載頁面的相同URL加載styleclass? 有人可以幫助找出發生這種情況的原因嗎?任何幫助將不勝感激。

+0

+1有趣的問題。 – Marko 2010-10-09 02:16:35

+0

它被稱爲「元素」,而不是標籤。適當的引用(即使用'''而不是兩個撇號)將解決問題。 – You 2010-10-09 02:26:15

+0

適當的引用解決了問題。但我更感興趣的是找出額外的單引號導致問題的原因。:) – Jish 2010-10-09 02:30:07

回答

0
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> 
    <head>   
    </head> 
    <body> 
     <table width="100%" cellspacing="0" cellpadding="0" border="0" class="mainOutterTable"> 
      <tbody> 
       <tr> 
        <td> 
         <table class="layoutColumn" cellpadding="0" cellspacing="0"> 
          <tr> 
           <td style="width:100%;" valign="top"> 
            <table class="layoutRow" cellpadding="0" cellspacing="0"> 
             <tr> 
              <td valign="top" width="910"> 
               <table class="layoutColumn" cellpadding="0" cellspacing="0"> 
                <tr> 
                 <td style="width:100%;" valign="top"> 
                  <table class="layoutRow" cellpadding="0" cellspacing="0"> 
                   <tr> 
                    <td valign="top" width="294"> 
                     <table class="layoutColumn" cellpadding="0" cellspacing="0"> 
                      <tr> 
                       <td style="width:100%;" valign="top"> 
                        <a name="7_N1K8HIC0GOO780I2B1KASD3047"></a> 
                        <div class="wpsPortletBody"> 
                         This is a sample textf 3. 
                         <link rel="stylesheet" type="text/css" title="Style" href=''/> 
                        </div> 
                       </td> 
                      </tr> 
                     </table> 
                    </td> 
                   </tr> 
                  </table> 
                 </td> 
                </tr> 
               </table> 
              </td> 
             </tr> 
            </table> 
           </td> 
          </tr> 
         </table> 
        </td> 
       </tr> 
      </tbody> 
     </table> 
    </body> 
</html> 

我能夠重現一個測試頁面上的問題。 alt text

這在第5.2節中提到http://www.apps.ietf.org/rfc/rfc3986.html#sec-5.2 如果相對路徑爲空,則目標URI是基本路徑。 if(R.path ==「」)then T.path = Base.path;

1

此解釋來自this article on Yahoo Developer site。第避免空洞圖片src

When an empty string is encountered as a URI, it is considered a relative URI and is resolved according to the algorithm defined in section 5.2. This specific example, an empty string, is listed in section 5.4.

儘管尚不清楚這種行爲是否會影響href與否(本文主要關注於空src)。但看起來像它:

Hopefully, browsers will not have this problem in the future. Unfortunately, there is no such clause for <script src=""> and <link href="">. Maybe there is still time to make that adjustment to ensure browsers don't accidentally implement this behavior.

注:我從來沒有遇到這樣的行爲,所以它只是理論上的答案:)