我试图在jQuery Mobile 1.3.2 pageremove事件上获取旧页面的url / filename(左边的那个)。
这适用于Chrome和Firefox:
$(document).on("pageremove", function(e){ console.log( $.mobile.path.parseUrl(e.target.dataset.url).filename); });但不是在Internet Explorer中。
如何以跨浏览器兼容的方式执行此操作?
更新
我可以通过在pageshow事件上设置变量来间接地做到这一点,
$(document).on("pageshow", function(e){ last_page = $.mobile.path.parseUrl(e.currentTarget.URL).filename; });然后访问pageremove上的那个。
不过直接得到它会很好。
I am trying to get the url / filename of the old page (the one being left) on a jQuery Mobile 1.3.2 pageremove event.
This works in Chrome and Firefox:
$(document).on("pageremove", function(e){ console.log( $.mobile.path.parseUrl(e.target.dataset.url).filename); });But not in Internet Explorer.
How can I do this in a cross-browser compatible way?
Update
I can do this indirectly by setting a variable on a pageshow event,
$(document).on("pageshow", function(e){ last_page = $.mobile.path.parseUrl(e.currentTarget.URL).filename; });and then accessing that on pageremove.
It would be nice to get it directly though.
最满意答案
似乎无法以跨浏览器兼容的方式查看页面的文件名保留在pageremove事件上。 即你无法看到哪个页面(可能)被删除。
但我之前添加到问题本身的解决方法对我来说很好:
$(document).on("pageshow", function(e){ last_page = $.mobile.path.parseUrl(e.currentTarget.URL).filename; }); $(document).on("pageremove", function(e){ console.log(last_page); });这是因为pageshow事件发生在pageremove事件之后,因此“onPageremove”中的last_page仍然包含显示页面时的值。
It appears not to be possible to see the filename of the page being left on a pageremove event in a cross-browser compatible way. ie you can't see which page is (potentially) being removed.
But the workaround I added earlier to the question itself has worked fine for me:
$(document).on("pageshow", function(e){ last_page = $.mobile.path.parseUrl(e.currentTarget.URL).filename; }); $(document).on("pageremove", function(e){ console.log(last_page); });This works because the pageshow event happens after the pageremove event, and so last_page within the "on pageremove" still contains the value from when the page was displayed.
更多推荐
发布评论