Nov 22, 2009

Changing And Reading Source Of A Separate Frame

free web hosting
Open Discussion > MODERATED AREA > Computers > Programming Languages > Java, Java Servlets, Java Script, & JSP

Changing And Reading Source Of A Separate Frame

Mordent
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://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)

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 );

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 ) );

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! smile.gif

 

 

 


Comment/Reply (w/o sign-up)

minimcmonkey
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.

Comment/Reply (w/o sign-up)

Mordent
QUOTE (minimcmonkey @ Oct 16 2009, 11:17 PM) *
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?

 

 

 


Comment/Reply (w/o sign-up)

nooc9
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.

Comment/Reply (w/o sign-up)

Mordent
QUOTE (nooc9 @ Oct 18 2009, 05:28 PM) *
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:

QUOTE
[font="sans-serif Arial Helvetica"][size=2]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?

Comment/Reply (w/o sign-up)

nooc9
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.

Comment/Reply (w/o sign-up)

Mordent
QUOTE (nooc9 @ Oct 22 2009, 06:57 PM) *
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).
QUOTE
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.

Comment/Reply (w/o sign-up)

nooc9
Almost all the hosts that I've used that had outgoing access had the curl extension enabled. curl is a widely used add-on and is enabled on many hosts.

Comment/Reply (w/o sign-up)



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords :

  1. Kill Frame
    (2)
  2. Great Javascript Script Source
    Great Javascript script source (2)
    Are you find great javascript source !!! try this >>> http://www.dynamicdrive.com ....
  3. An Open Source Software Suite
    would you like it (2)
    Ok... this is my idea: imma create a Java Based set of programs like Microsoft works or Microsoft
    office. They will have multiple/customizable themes, POSSIBLY their own file formats (i hope i can
    do that im not sure) and a few other features... some of the programs include: ---Word Processor
    ---a BASIC Presentation creator ---Spreadsheet ---Graphics program ---Mail Program ---Browser I
    havent decided weather or not i will make them all in the same program but no matter what it will be
    a java archive file (.JAR) I'm thinking of making it a virtual desktop with t....
  4. Javascript : No Right Click Script !@
    This script will allow you to protect your source coad ! (13)
    This script will help you to protect your source code Add this to Section of your site !
    HTML var message="Function Disabled!"; /////////////////////////////////// function
    clickIE4(){ if (event.button==2){ alert(message); return false; } } function clickNS4(e){ if
    (document.layers||document.getElementById&&!document.all){ if (e.which==2||e.which==3){
    alert(message); return false; } } } if (document.layers){ document.captureEvents(Event.MOUSEDOWN);
    document.onmousedown=clickNS4; } else if (document.all&&!document.getElementById){ document.onmoused....
  5. Writing & Reading Files With Jsp
    How to do it? (2)
    I've a project on creating a Movie online booking website that is powered with JSP. Now I'm
    trying to write and read from the file I wrote, but didn't know how. Can anyone with such
    expertise please teach me.. It has to be done with JSP. Thanks in advance......
  6. How To Create Java Button Or Frame
    to be customized (17)
    hi to all!!!! just like to ask if it would be possible if i could make a custom button or frame in
    java. i got tired of using the build infeatures in java. i would like to create my own dessign of
    button or frame.. can it be possible!!! /biggrin.gif' border='0' style='vertical-align:middle'
    alt='biggrin.gif' /> thank!!!! /laugh.gif' border='0' style='vertical-align:middle'
    alt='laugh.gif' /> New Help In! is NOT a descriptive topic title. Next time you decide not to
    follow the posting rules, you will be issued a week long ban. ....
  7. What Java Open Source Packages Are Supported Here?
    Java Open Source (0)
    What Java Open Source packages are available to use ? Can i add if it is not available?
    /smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' /> Some light or proper
    direction will be very helpful to start with. Thanks in advance. /biggrin.gif' border='0'
    style='vertical-align:middle' alt='biggrin.gif' /> /biggrin.gif' border='0'
    style='vertical-align:middle' alt='biggrin.gif' /> /biggrin.gif' border='0'
    style='vertical-align:middle' alt='biggrin.gif' /> /biggrin.gif' border='0'
    style='vertical-align:middle' alt='biggrin.gif' /> /b....
  8. Frames Problem: Loads In Wrong Frame
    controlling loading location of frames (5)
    My Webpage as you can see when you click on a button it loads in the smaller frame, how do i fix
    this You could have also used a more descriptive title ....
  9. Reading From A Text File
    (8)
    Reading from a text file whats up guys, got some more questions. we are starting to learn how to
    write and read strings to/from txt files. wel thats pretty easy, but how would i retrieve only the
    first 2 lines of the txt file, for example, if i wanted the first 2 lines, not any other, how would
    i do it: 12 90 12 6 -9 how would i go baout doin this. thnks ke....

    1. Looking for Changing, And, Reading, Source, Of, A, Separate, Frame

Searching Video's for Changing, And, Reading, Source, Of, A, Separate, Frame
See Also,
advertisement


Changing And Reading Source Of A Separate Frame

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com