I have two HTML files (index.html and toolbar.html), index.php containing a frameset with two frames (one with a name of "toolbar", the other "main") in it. The first frame has an attribute of "src=toolbar.html", the other has "src=http://www.someexternalsite.com", which is on another domain (that I don't own). Essentially I'm creating a toolbar for use with the game to perform some of the most common functions, like direct links to pages that require a few clicks in the game but are used often and timers you can use to remind you to perform certain actions.
Background out of the way, here's my goal: to be able to have a button in toolbar.html that when clicked stores the page that the other frame is on (URL) and then changes it to "settings.html" (in the same folder as index.html and toolbar.html). Clicking the button again (or a separate button, haven't decided exactly which yet but doesn't really matter, I can build it in however after I know how) will change the other frame back to the page it was just on (which would be roughly of the format "http://www.someexternalsite.com/blah/blah/blah.php").
Any suggestions? So far I've tried the following basic approaches:
CODE
var frameLastLocation = parent.main.location.href;
parent.main.location.href = "settings.html"; (or frameLastLocation, the idea is the same)
parent.main.location.href = "settings.html"; (or frameLastLocation, the idea is the same)
This allows me to change the contents of the frame to whatever I want (just put it in place of "settings.php"), which is fine. For some reason, though, frameLastLocation contains "about:blank" (tested by using "alert (frameLastLocation);" straight after it). As a test, arranging I arranged the JavaScript as below:
CODE
parent.main.location.href = "settings.html";
alert ( parent.main.location.href );
alert ( parent.main.location.href );
This didn't provide a popup box, which I assume happens when the argument provided to alert() is empty? As a further test, I changed the code to this:
CODE
parent.main.location.href = "settings.html";
alert ( typeof ( parent.main.location.href ) );
alert ( typeof ( parent.main.location.href ) );
This had a popup box with "string" as its contents. It seems that you can write to parent.main.location.href, but you can read to it? Bear in mind that the initial URL of the main frame is "http://www.someexternalsite.com", and it displays that fine.
One alternative to the location.href method I've looked in to is changing the src attribute of the frame itself, but after a bit of research (link) it seems that this approach won't work, making me believe I'm on roughly the right track with location.href, just it needs some more refining.
If any more of the code (minimal as it is, I'm rebuilding the toolbar from scratch) is needed, just let me know.
Cheers in advance!
EDIT: Just had a bit of inspiration: rather than storing the previous location in a variable, simply using window.history.back() can work nicely. However, it's by no means ideal, as I plan on having a number of different sources available rather than just one. It's a temporary workaround that lets me get on with the rest of the work while I wait in anticipation of any answers you folks have!


