2013-05-03 35 views
2

我正在使用JavaScript錯誤日誌記錄工具在我的移動網站上記錄任何JavaScript錯誤,並且看到大量(一個月內22,000個)這個錯誤的:addthis_widget.js拋出無法讀取Android和Chrome上的null錯誤屬性'_pmh'

Uncaught TypeError: Cannot read property '_pmh' of null

我可以從它是從腳本發起addthis_widget.js代碼中看到。

我也可以告訴大家,它不僅影響手機Android和谷歌的Chrome瀏覽器,這些特別:

安卓4.0,安卓4.1,安卓4.2,鉻11,鉻18,鉻25,鉻26,鉻27時,Chrome移動18,瀏覽器25移動時,Chrome移動26

我使用以下外部JavaScript包括:

http://s7.addthis.com/js/250/addthis_widget.js#username=xa-4b6adff375a64db9

,並具有以下配置對象集:

<script type="text/javascript"> 
    var addthis_config = { 
     data_ga_property: 'UA-18721873-1', // real GA profile hidden for privacy purposes   
     data_ga_social: true 
    }; 
</script> 

有什麼我可以做的,以防止在這些瀏覽器上發生這麼多次這種錯誤?

回答

2

我找到了這個問題的原因,它是下面的代碼。

if (window.addthis) { 
    window.addthis = null; 
    window._adr = null; 
    window._atc = null; 
    window._atd = null; 
    window._ate = null; 
    window._atr = null; 
    window._atw = null; 
} 

這是一個嘗試清理在頁面之間動態移動以防止內存問題時出現的對象。現在

前頁針對此問題提供支持,他們的支持部門發給我下面的鏈接:

http://www.addthis.com/blog/2013/05/07/a-brief-history-of-using-addthis-dynamically/#.Uklx4RCKyas

和下面的解釋/信息:

Along with other information from my peers and such, I've come up with the proper code which should be executed when moving from virtual page to virtual page such as in your mobile application. Rather than nulling any of the AddThis related objects, they must be left alone.

When the page URL or Title (or any other AddThis configuration option) that you want to be used by our buttons changes, you should execute our method:

addthis.update(type, key, value)

It takes the three parameters: type, key, value.

Type is either "share" or "config". The key is the same key you would set according to our API documentation. What you likely need to know are just the two keys: "url" and "title". The value is of course the value you want those options to have.

After you have updated all of the options you need to update using that method, you need to invoke this method:

addthis.toolbox(cssSelector)

The cssSelector is usually going to be ".addthis_toolbox" but if for some reason you don't want to refresh all of your toolboxes, you can be more specific about it.

Once you have made those changes to your code, I believe that our tools will work properly for you and that there will be no more "null object" related javascript errors.

You can look at this JSFiddle to see an example of dynamically changing content: http://jsfiddle.net/j5addthis/r6Utv/

0

我遇到了同樣的問題,但是通過更改以下代碼,只需將您使用的腳本從addthis升級到3.0版,即可在某一時刻修復上述特定情況:

http://s7.addthis.com/js/250/addthis_widget.js#username=xa-4b6adff375a64db9 

要這樣:

http://s7.addthis.com/js/300/addthis_widget.js#username=xa-4b6adff375a64db9 

在這裏閱讀更多:http://support.addthis.com/customer/portal/questions/1021465-addthis-widget-js-throwing-cannot-read-property-pmh-of-null-error-on-android-and-chrome

不過請注意,正如我上面提到的,我的問題仍然存在,甚至與3.0版本堅持儘管AddThis服務檯聲明應該有效。

+0

嗨卡蘭,你可能會注意到addThis支持鏈接起源於我自己(crmpicco)。我確實從250更新到300,但問題仍然存在。我已經跟進了一個支持請求來添加這個,但他們已經安靜了。它似乎更經常發生在移動設備上,但它並沒有被本地化爲一個操作系統或設備。 – crmpicco 2013-07-15 11:32:35

相關問題