admin管理员组

文章数量:1023794

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>

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>

本文标签: javascriptdocumentonpageshow is not a functionStack Overflow