最近在做項目的時候,實現一個很簡單的加入收藏夾的功能,網上代碼多的是,如下就是我整理的一個版本
注:如果該頁面沒有放在服務器(如tomcat)上 ,而是放在普通文件夾中(如桌面),則瀏覽器狀態欄會報沒有權限的錯誤,具體原因有待研究,不屬于本次討論的范圍。
我將以上代碼放到服務器中并執行時,IE7瀏覽器狀態欄報錯,“找不到元素”,但同事的瀏覽器可以正常訪問,也能添加到收藏夾。故確定是我的瀏覽器的問題。
Google搜到國外一個帖子,如下:
GWT not working on Internet explorer 7 (IE7) giving "Element not found" javascript error
GWT web application started to give "Element not found" javascript error message on Internet Explorer 7 (IE7)? This application worked fine on Internet Explorer 6 and Firefox 2. Now your best guess would be; GWT not working on IE 7 properly. Wasn't it?
But the scenario became confusing and unbelievable because your application worked fine on IE7 in some machines while not on some others. Have you faced this issue? Then the below solution is for you.
This issue can be fixed by a making a change on windows registry.
Steps to follow are;
1. Open up the Registry editor - type regedit on command prompt.
2. Look for the key shown below
HKEY_CLASSES_ROOT\TypeLib\{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}\1.1\0\win32
3. Click on the "Default" row and see the value there. If it's value is "C:\WINDOWS\system32\shdocvw.dll", then that is what causes the above mentioned issue. If you have installed Windows in a different drive; C:\ must be replaced with the that letter.
4. Replace that value with "C:\WINDOWS\system32\ieframe.dll".
5. Now restart IE7, and load your GWT application.
于是猛然想起,我之前也裝過IE8的測試版,但是后來又被我卸載了,原因就在于此,按照上述方法,更改了注冊表,重啟IE7,運行沒有問題。
另外也順便收藏了IE和FF都適用的方法:
寫完手工。