-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JavaScript variables not retained after card flip #2868
Comments
Reported by
|
Reported by |
I am still experiencing this issue 3 years later it is quite annoying. I've found someone who seems to have found a workaround but I can't seem to make it work (I'm not experienced with javascript) |
There was another issue recently which led to the discovery (possible not for the first time) that AnkiDroid does not share the WebView between the front and the back during a flip - it loads a new one. The other issue used an HTML+javascript local storage workaround in order to persist / load state between the two webviews, and it was sufficient for that problem. Which is just to say that there are workarounds even with the limitation of not maintaining WebView state across the note flip from front to back, but other than that no one has yet proposed a pull request that shares the webview between the two |
Well that's a real bummer, it doesn't looks like it's gonna be fixed any time soon even though it seems like a basic feature ankidroid should have implemented long ago. I guess I'm stuck with fields getting randomized two times, feels bad. |
while I understand the frustration, just remember "ankidroid" is "us", I only started working on it myself a few months ago. I found a reference to the other person who overcame this limitation - has re-usable code and everything over on his github... #4868 (comment) |
#493 was also meant to address this use case, it would be nice if someone with some knowledge on the topic could write some nice instructions and put them on the advanced formatting wiki |
Don't get me wrong I genuinely admire the work being done here, I just get obsessed over things I can't solve and my poor coding skill surely is not helping. |
@timrae Also here is the Anki deck I've been talking about if anyone is interested: https://drive.google.com/open?id=1FhJBal0-NBhQ85wsvWWocRnnSJZhPkMF |
@epistularum that's exactly it - there are ways to preserve state even though AnkiDroid doesn't use the same WebView. The anki-canvas repo linked in #4868 is a great piece of work but uses a lot of technology to get the job done and has a specific use case (an embeddable drawing object - no small thing, justifying all the ancillary technology). The technique of state storage is the important thing here though - and that's in these lines if I'm reading correctly (the store declaration, and load + save methods): |
@mikehardy That's quite the particular use case indeed. If I were to use anki-canvas would it solve the issue of cards being randomized two times? Because I might switch to for a while anki-canvas if it's capable of doing so (assuming I know how to even install it). The technique of state storage was also mentioned on the link with the workaround I posted up there (even though I'm too much of a monkey to even make it work on my own deck). I'm sure the piece of code you just linked is quite remarkable but to be honest I have no understanding of its meaning. |
For DoJG, you can use this template. (Surprise: me) |
@hssm I'd like to keep the current formatting of my cards, is that possible to achieve? |
You just need to apply the formatting parts from your template to the one Houssam has given you. I hope you're not expecting someone to do all the work for you. |
It's probably easier for you to pluck out the small portion of javascript that decides the random number (which is clearly delineated) and use that in your existing template. But yeah, you're on your own with that one. |
@timrae Of course I'm not. |
@timrae @hssm I'm really sorry, I have no knowledge whatsoever of coding. I managed to modify the code to only have one example phrase. This is what I currently have: https://imgur.com/a/UUUxEVz |
Ok I've found a workaround, I'll post the result here. |
Here's what I managed to Frankenstein: Thanks a lot! Sorry to have bothered you. |
Just a quick note on this one as I was in the area yesterday. We do re-use the WebView across card flips (and card reviews), so this is more possible than I thought. The state is still obliterated across card flips because we do a "loadDataFromBaseURL" (or similar, I might have the API call name not exact). In order to preserve state across card-flips I'd suppose we'd need to rewrite the DOM for the answer or somehow do the HTML differently. Or you could use cookies perhaps (its the same WebView). The solutions that work so far are using HTML5 local storage which is effective but maybe not fully necessary in other words. |
Hello 👋, this issue has been opened for more than 2 months with no activity on it. If the issue is still here, please keep in mind that we need community support and help to fix it! Just comment something like still searching for solutions and if you found one, please open a pull request! You have 7 days until this gets closed automatically |
Hello 👋, this issue has been opened for more than 2 months with no activity on it. If the issue is still here, please keep in mind that we need community support and help to fix it! Just comment something like still searching for solutions and if you found one, please open a pull request! You have 7 days until this gets closed automatically |
Closing in favor of #14302 |
Originally reported on Google Code with ID 1966
Reported by
Taoluo93
on 2014-01-15 13:14:25- _Attachment: [random display3.0.apkg](https://storage.googleapis.com/google-code-attachments/ankidroid/issue-1966/comment-0/random display3.0.apkg)_
The text was updated successfully, but these errors were encountered: