Why is javascript:history.go(-1); not working on mobile devices?

岁酱吖の 提交于 2019-12-12 16:09:05

问题


First, some background:

I have an application which presents a search page (html form) to the user. Once criteria have been filled out and the Search button is clicked, results appear beneath the criteria section. In the list of results, you can view the detail of an individual result by clicking a link which takes you to a new page. Within the detail page, I have included a Back to Results link like so:

<a href="#" onclick="history.go(-1);return false">Back to Results</a>

This works great in IE8/9, Safari, Firefox and Chrome on the desktop. However, it does not work on my Android phone, my Android emulator or the iPhone 3G. I should note that when I use the link on the desktop I am immediately returned to what seems to be a cached copy of my search page with results, and I'm placed at the same scroll position within the results. On the mobile devices, it appears as though the page reloads from the server, my search criteria disappear, and there are no results.

If anyone has any ideas on where to start looking for a solution, I would really appreciate it! I can also provide more detail as necessary.

Thank you and regards, CN


回答1:


Use:

    <a href="javascript:history.go(-1)">Back to Results</a>

ie not in "onclick" but in "href" - that's work




回答2:


For Android, you need to enable javascript in the webview :

webView.getSettings().setJavaScriptEnabled(true);



回答3:


What method are you using to pass filters to your search page? POST or GET?

If you're using a POST then you would have to resubmit your filters when they go back, otherwise your page won't have anything to filter on.

Try switching to a GET and see if that works.

I think the important distinction is that it is working (i.e. sending you back a page), but your mobile device isn't reposting your form fields?



来源:https://stackoverflow.com/questions/4961376/why-is-javascripthistory-go-1-not-working-on-mobile-devices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!