Jump to content
xisto Community
Sign in to follow this  
Mordent

Changing And Reading Source Of A Separate Frame

Recommended Posts

Somewhat linked to my previous topic, I thought I'd start another one with this separate question. If a mod disagrees with this, feel free to merge the two. A bit of context, first:

 

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://forums.xisto.com/no_longer_exists/;, 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://forums.xisto.com/no_longer_exists/blah/blah/blah.php;).

 

Any suggestions? So far I've tried the following basic approaches:

 

var frameLastLocation = parent.main.location.href; 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:

 

parent.main.location.href = "settings.html"; 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:

 

parent.main.location.href = "settings.html";   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://forums.xisto.com/no_longer_exists/;, 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! :P

Edited by Mordent (see edit history)

Share this post


Link to post
Share on other sites

I dont really see why you need to remember the last frame if you are making a toolbar.Just have a link to all the [ages you need the most in the toolbar frame which targets the main frame.

Share this post


Link to post
Share on other sites

I dont really see why you need to remember the last frame if you are making a toolbar.

Just have a link to all the [ages you need the most in the toolbar frame which targets the main frame.

I already have a link to the pages I need the most in the toolbar frame (with the main frame as the target). However, as I'm planning on letting others use the toolbar I'm going to let them customise it to the pages they need the most (as well as various other customisation options, but suffice to say an area as large as the main frame is needed).

 

I currently have a working toolbar that has some of the features I want in the second version in it, and at the moment you can customise them in the toolbar frame (the div with the toolbar itself and another with the toolbar options toggle between display="none" and not), but already the amount of customisation has meant a scrollbar is pretty much a necessity unless you have an outrageously tall screen. In order to solve this, as well as have extra space for the additional customisation, I also want to have the main frame switch to the settings.html file and back to the last game page you were on when you press a certain button in the toolbar.

 

As I mentioned in my edit, I realise that this can be done with the window.history.back method, but one of the additional functions of the toolbar that I want to introduce is, essentially, a scribble pad where you can write down any notes, pre-write any forum posts (as the game has an annoying tendency of refreshing the page half way through writing a long post and therefore meaning you lose it) and any other use people care to have for it. Naturally this should go in the main frame as well.

 

In a nutshell, the toolbar will have its own navigation menu (which I have mimicking the appearance of the game one, to help it blend better), with links (via javascript) to change the contents of the main frame to the toolbar's settings page, the toolbar's scribble pad and the game page (last viewed page is preferable, to save you having to renavigate to it after changing, say, the toolbar's preferences). Only the relevant two links will be displayed at any one time (as clearly you're already on one of the pages).

 

Whenever one of the links is pressed and the current contents of the main frame is the game then I want its location stored (or title, but I've worked out from my other topic that that's not really possible) so that I can have the "Game" link go back to that page when its pressed.

 

Is this achievable using JavaScript?

Edited by Mordent (see edit history)

Share this post


Link to post
Share on other sites

Why not try wrapping the game in php. When someone loads your page, you load the game page and inject whatever you want into the page and also filter the links and change them so they will load through your script. You would not have the domain security problem.

Share this post


Link to post
Share on other sites

Why not try wrapping the game in php. When someone loads your page, you load the game page and inject whatever you want into the page and also filter the links and change them so they will load through your script. You would not have the domain security problem.

Sounds like a definite plan, but I'm not entirely sure how to go about implementing it. When you say "wrap the game in PHP" what sort of method/function are you referring to? If it's possible then it's most definitely an excellent solution to my problem.

 

Other than this, I've been looking in to a few other ways of achieving my goal, but so far with very limited success. Despite finding a very promising page that suggested you could read the URL of any page in the history. This would be pretty much ideal for what I need it for (simply check the last page's URL after loading the new one and storing it in a variable for later loading), however I haven't been able to get any meaningful output from it. Perhaps another set of eyes could make sense of this for me, or perhaps the quote below explains why I have this issue:

 

Getting the value of this property requires the UniversalBrowserRead privilege.

I'm guessing that this is some client-side setting that essentially stops me from using this method at all?

 

EDIT: After a lot of Googling (a surprisingly tricky subject to find proper information about, I have to admit), I've worked out what UniversalBrowserRead is, though I'll admit my definite uncertainty on the all important question: how do I get it enabled?

 

I suppose this could be viewed as being a question for a different topic, but as it still pertains to my task I'll carry on the discussion here. From what I can work out, the most effective means of obtaining UniversalBrowserRead (as well as a stack of other permissions) is to have a security certificate. These (I believe) remove the concept of risk to the user (by not providing any warning?) and cost some amount ranging from the low tens of dollars to the high hundreds. For the sake of my bank balance, I'm not exactly in favour of this method.

 

My alternative, or at least the only one that I can see assuming that it's provided, is to have a warning pop up every time I try to enable the permission, which isn't such a bad thing given that the site is only a basic one that a few users will actually use, and given that I can explain to them why I need the permission (which would also let me do a heap of other cool, snazzy things) then it's an acceptable workaround.

 

I believe that there will be some serious browser-compatibility issues with it (three cheers for Internet Explorer! ...No? Anyone?), but again assuming that this isn't a problem for my user-base (all faithful Firefox users, as far as I know), the only real problem comes down to actually implementing it. Any suggestions as to alternatives, before I start delving in to this idea?

Edited by Mordent (see edit history)

Share this post


Link to post
Share on other sites

Anything that has to do with browser security will probably require the user to manually change some setting.If you want to create a wrapper then you will need to use something like curl, if using php, to handle cookies and stuff.

Share this post


Link to post
Share on other sites

Anything that has to do with browser security will probably require the user to manually change some setting.

Not as such. I looked in to it and it seems that it's pretty much universally "off" unless the user manually (i.e. with a popup box) turns it "on" if the file is stored locally (doesn't work via http protocol), or can be turned "on" by your site being signed using a security certificate (again with a popup, but this time it's allowed online).

If you want to create a wrapper then you will need to use something like curl, if using php, to handle cookies and stuff.

Nice find with cURL there, looks quite nifty though, I believe, not quite what I'm after for use with frames. Yes, I'm aware that frames are "bad" in a lot of people's eyes, but as far as this objective is concerned they're certainly a fairly nice method.
That said, I can most definitely see how it could be used (essentially have the "main" frame on my hosting, but as a .php file, and let it load the contents of the game page). I can then use a chunk of regular expressions and various other searching and replacing methods to alter the contents as I please, or alternatively just use JavaScript to do it. One minor qualm that I have with this approach is that it relies on a non-core extension to PHP, which just rubs me the wrong way. While I'm all for clever little libraries and so on, I definitely prefer not relying on some additional piece of software that I'd have to install on my hosting should I ever want to use my code. It's a little issue, sure, but I'm in favour of not using it nonetheless.

For now I reckon I'll be sticking to a much more basic toolbar, then working out how I can get a security certificate (the various sorts, how I pay for it, etc.) that lets me use the functionality I want to (which is part of a default server build).

Cheers for the suggestion, however, and it's one that I'll look in to as a cheaper means of doing what I want to do.
Edited by Mordent (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.