Replace window.onload with jQuery alternative

6.76K viewsIssues
3

Hi,

This is David from the WPML compatibility team. Im writing about a problem we found when using WPML with your plugin which was initially reported here:

https://wpml.org/forums/topic/wpml-doesnt-recognize-french-as-a-separate-language-in-menus/

The problem is that you are manipulating window.onload directly in ap-admin.js. This can lead to compatibility problems with other plugins. In general, its a good idea to avoid assigning functions directly to onload.

You are already using jQuery, why not use its method instead?

jQuery( window ).load(function() {
// Run code
});

Let me know if you are willing to include this fix to provide our common users with a smoother experience.

Best,

David García Watkins
WPML Compatibility Team
OnTheGoSystems
The makers of WPML, Toolset and ICanLocalize

0

I still see window.onload still being used here:

https://github.com/anspress/anspress/blob/4.1.0/assets/js/ap-admin.js#L23

commented on answer

Ah, I misunderstood. Now its fixed.

0

Hello David,

I don’t see any problematic JS in ap-admin.js in our latest beta version. I remember that I deleted many old codes in beta version.

Please conform if I can assume this issue as already fixed. Here is the link to latest ap-admin.js file:

https://github.com/anspress/anspress/blob/4.1.0/assets/js/ap-admin.js

0

Hello David,

Glad to see you here.

You are right. That snippet was written in initial version of AnsPress and I have not done anything to improve it. I will push a fix today.

Thanks for reporting.