Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pageShow event in javascript

I have the following code:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="http://code.jquery.com/jquery-1.4.4.min.js"></script>

    <script type="text/javascript" language="javascript">
    $( function() {
        window.onload = function () {
            alert('This page was just hidden:');
        }
    });
    </script>
</head>
<body pageshow="alert('Done');">
<div id="mypage" data-role="page"  data-theme="b"> 
    <div data-role="header">
        <h1>Page 2</h1>
    </div> 
    <div data-role="content">
        <p>This is page 2.</p> 
    </div> 
</div> 
</body>
</html>

But the pageShow event is not firing in IE. Any idea why?

like image 737
facebook Avatar asked Jun 15 '11 19:06

facebook


3 Answers

It is a mispell; in the body's tag, the name of the event is "onpageshow" and no "pageshow".

...
<body onpageshow="alert('Done');">
...

For IE pageshow event is not supported.

like image 79
sahid Avatar answered Sep 30 '22 06:09

sahid


OnPageShow and OnPageHide are new HTML5 event attributes, and as such will only enjoy limited browser support (at the time of writing)

Its more likely that later versions of incumbent browsers will support it. Firefox certainly will, as will Safari according to this article.

I couldn't find anything that stated it definitively, but I would say that its likely that these events aren't supported in the version of IE that you are using. Can you maybe post this information for clarification.

Hope this helps

like image 21
James Wiseman Avatar answered Nov 13 '22 18:11

James Wiseman


Your code is inconsistent. You're using jQuery.ready, onload, onpageshow at the same time. Seems like a good place to start your refactoring process.

What do you really want to achieve?

like image 8
25 revs, 4 users 83% Avatar answered Nov 13 '22 17:11

25 revs, 4 users 83%