How to make the browser back button work for a Flash-based Website?
Is i开发者_高级运维t possible to make the flash content go back to some previous frame when the user clicks on the back button in the browser? Similarly, can the the refresh button be used to refresh to the same frame and not go back to the starting frame?
It depends on how you build it. First of all, you need to import something called SWFAddress. In order to use SWFAddress you need to make sure you're embedding your Flash using SWFObject, not just object/embed tags.
SWFAddress lets you append anchor tags to your url. What this allows you to do is change the URL in a way that the browser can understand without forcing a refresh of the page.
So for instance, if my app is at www.mypage.com/flash.html and I install SWFAddress I can set it up so that when I press a button to go to page 2 the following happens:
- SWFAddress changes my URL to www.mypage.com/flash.html#page2
- The JavaScript SWFAddress files notice this change and inform Flash.
- Flash says "Oh look there's been a URL change and someone is passing me the value "page2" - what should I do with that?
- You can set up a switch statement that will allow flash to respond to these events in intelligent, predictable ways - for instance, you can say "if the url changes to 'page2' then gotoAndStop(2)" if that's how you're running things.
I wouldn't necessarily be doing it with Frames, though - what you really want are functions to control the way Flash behaves. So instead of sticking all of your page two content into frame 2, you'd create function gotoPage(2) and put your logic there.
As far as refreshing a frame, again that's going to depend on how you code it - but if someone hits refresh in the browser it will always refresh the browser window. With SWFAddress, though, if you have it set up right it will always take them to the destination that you've linked to the anchor tag.
Does that help? Any questions?
Try using SWFAddress. Here is simple demo. Lee has a nice video tutorial to get you started.
The browser buttons work on web file documents, like html, htm, php, cfm, jsp, etc. When your browser a flash page, your remaining on the same, and the content changes based on how it is programmed and how the user is interacting with the document. So no, those buttons don't work as you'd like to for a flash document.
精彩评论