2012-01-26 43 views
1

我有這種情況 - 在我們的ASPX站點上,使用DEVExpress,只在IE 8(原始的IE 8模式不是IE 9)在登錄頁面上我們經常出現一個錯誤:使用ASPX和DEVExpress覆蓋IE 8上的JS focus()方法...

Can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus. 

所以 - 我研究並發現某些東西試圖集中某些看不見的東西。所以我嘗試了這個解決方案 - 重寫focus()方法。下面是一個簡短的HTML頁面示例:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
    <head> 
    <title>AccuLynx</title> 
    <script type="text/javascript"> 
     HTMLInputElement.prototype.focusCpy = HTMLInputElement.prototype.focus; 
     HTMLInputElement.prototype.focus = function() { 
     if(this.style.display != 'none' && this.style.visibility != 'hidden' && !this.disabled && this.type != 'hidden') { 
      HTMLInputElement.prototype.focusCpy.apply(this, arguments); 
     } 
     } 
    </script> 
    </head> 
    <body> 
    <input type="submit" id="my_link" style="display:none;" value="dfsdfd" /> 
    <script type="text/javascript"> 
     document.getElementById('my_link').focus(); 
    </script> 
    </body> 
</html> 

然後在測試頁上一切看起來不錯,但在真實網站上 - 不是。

JS代碼是第一個被執行的東西之一 - 在第二個JS文件(第一個是JQuery插件)的開頭 - 但它不起作用。

任何意見表示讚賞。

+0

我會先嚐試找到發出焦點語句並防止發生這種情況的代碼。如果這是不可能的,你可以嘗試處理錯誤,並且如果將焦點設置爲允許的元素。 –

+0

這是個奇怪的問題。最好聯繫DX並要求他們解決問題。 – Mikhail

回答

3

我找到了解決辦法:) ......改變了JS代碼到這一個:

HTMLInputElement.prototype.focusCpy = HTMLInputElement.prototype.focus; 
    HTMLInputElement.prototype.focus = function() { 
    if(this.style.display != 'none' && this.style.visibility != 'hidden' && !this.disabled && this.type != 'hidden' && this.style.width != '0px' && this.style.width != '0%' && this.style.width != 0) { 
     HTMLInputElement.prototype.focusCpy.apply(this, arguments); 
    } 
    } 

或者換句話說 - 我加了一些時間,我記得之後元素的寬度檢查,病因這個荒謬的瀏覽器 - IE瀏覽器經常呈現一些寬度和高度爲0px的元素。

現在它工作:)

+0

我們在DevExpress彈出式控件中遇到了類似的問題,這是由於寬度爲0的DIV導致的。這個答案幫助我們修復了IE8的行爲。 –

+0

試過這個解決方案,在我的本地機器上運行良好,但是在部署到服務器之後,出現**'HTMLInputElement'未定義**的錯誤。可能是什麼問題??? –

+0

你在嘗試使用哪種Internet Explorer? ... :) ... –