最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - document.onpageshow is not a function - Stack Overflow

programmeradmin4浏览0评论

I've the following javascript file:

onShowFunction = function(e){
   //Some JQuery code
}
window.onpageshow(onShowFunction);

The index console log appears:

[Error] TypeError: window.onpageshow is not a function. 
(In 'window.onpageshow(onShowFunction)', 'window.onpageshow' is null)
Global Code (scripts.js:58)

I don't understand how to resolve. Is that event defined in other way and it is not a function?

I've the following javascript file:

onShowFunction = function(e){
   //Some JQuery code
}
window.onpageshow(onShowFunction);

The index console log appears:

[Error] TypeError: window.onpageshow is not a function. 
(In 'window.onpageshow(onShowFunction)', 'window.onpageshow' is null)
Global Code (scripts.js:58)

I don't understand how to resolve. Is that event defined in other way and it is not a function?

Share Improve this question asked Mar 4, 2018 at 12:57 alessandro308alessandro308 2,1922 gold badges17 silver badges32 bronze badges 2
  • window.onpageshow is not a function , mean you have to assign your created function to this window variable like window.onpageshow = onShowFunction – Bourbia Brahim Commented Mar 4, 2018 at 13:11
  • 1 Read this – Mike Ezzati Commented Mar 4, 2018 at 13:47
Add a ment  | 

2 Answers 2

Reset to default 5

window.onpageshow is not default js function. Try this:

window.addEventListener('pageshow', function(event) {
    console.log('pageshow:');
    console.log(event);
});

In your case:

window.addEventListener('pageshow', onShowFunction);

Try this

window.addEventListener('pageshow', onShowFunction);

or

window.onpageshow = function(e) { //Some JQuery code }

or

<body onpageshow="onShowFunction(e)"></body>
发布评论

评论列表(0)

  1. 暂无评论