覆盖window = onload [英] Overriding window = onload
问题描述
我在wordpress中有一个页面,我希望通过用户角色插件进行密码保护。在直接页面上一切正常但我有一个页面 window.onload = function(){
完全覆盖了密码功能。
I have a page within wordpress that I want to password protect via a user role plugin. Everything works fine on straight forward pages but I have a page with window.onload = function() {
that completely overrides the password function.
我希望在检查用户是否登录后立即加载页面。
I want the page to load immediately after it's checked to see if the user is logged in or not.
更新:
我正在使用此插件,我只是拥有功能:
I'm using this plugin and I just have the function:
<script type="text/javascript">
(function() {
window.onload = function() {
var map = new google.maps.Map(document.getElementById('map'), options);
...
} } )
</script>
然后在这个div上加载:
Which then loads on this div:
<div id="map" style="width:100%; height:100%"></div>
推荐答案
而不是直接将其分配给 onload
property将其添加为事件监听器
Instead of assigning it directly to the onload
property add it as an event listener
https://developer.mozilla.org/en/DOM/element.addEventListener
你会IE版本需要使用 attachEvent
< 9。
You'll need to use attachEvent
for IE versions < 9.
http://msdn.microsoft.com/en-us/library/ms536343(v = vs.85).aspx
如果您使用的是jQuery或Prototype等框架,则可以将其抽象出来,这样您就不必担心不同的浏览器了。
If you're using a framework such as jQuery or Prototype this can be abstracted out so you don't need to worry about different browsers.
这篇关于覆盖window = onload的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!