Using method defined in frameset in frame

A

Andrew Poulos

I'm trying to use the String method parseJSON (that is created in the
javascript of a frameset) in one of the frames but I don't know how to
correctly reference it. This:

notes = str.parseJSON();

doesn't seem to work - I get the error "str.parseJSON is not a
function". And this:

notes = str.parent.parseJSON();

also gives a similar error. If I code directly into the frameset I get
the results I expect.

Now I'm not sure where the issue is. How can I use a method that's
defined in a frameset in a frame?

Andrew Poulos
 
P

Peter Michaux

I'm trying to use the String method parseJSON (that is created in the
javascript of a frameset) in one of the frames but I don't know how to
correctly reference it. This:

notes = str.parseJSON();

doesn't seem to work - I get the error "str.parseJSON is not a
function". And this:

notes = str.parent.parseJSON();

also gives a similar error. If I code directly into the frameset I get
the results I expect.

Now I'm not sure where the issue is. How can I use a method that's
defined in a frameset in a frame?

parseJSON is not a native function yet. If you use Douglas Crockford's
reference implementation the above code should work.

http://www.json.org/js.html

Douglas's code augments build in objects (eg String) and this is
considered a bad practice by many. Since it is a reference
implementation, his implementation is to show how JSON will work
eventually not necessarily how it should be implemented now.

Is the JSON from a trusted source? If so then you don't need to use
the parseJSON function which just checks the JSON matches a particular
regular expression. If it is a trusted source you can just do

eval('(' + str + ')');

which is what the json parser ends up doing anyway after the regexp
check.


Peter
 
P

Peter Michaux

I'm trying to use the String method parseJSON (that is created in the
javascript of a frameset) in one of the frames but I don't know how to
correctly reference it. This:

notes = str.parseJSON();

doesn't seem to work - I get the error "str.parseJSON is not a
function". And this:

notes = str.parent.parseJSON();

also gives a similar error. If I code directly into the frameset I get
the results I expect.

Now I'm not sure where the issue is. How can I use a method that's
defined in a frameset in a frame?


Oops. I think I read to fast. You are using the JSON library in the
parent? Something like this...

window.parent.String.prototype.parseJSON.apply(str)

Peter
 
A

Andrew Poulos

Peter said:
Oops. I think I read to fast. You are using the JSON library in the
parent? Something like this...

parent.str.parseJSON();

didn't work (it gave the error "parnet.str jas no properties") but the
following did:
window.parent.String.prototype.parseJSON.apply(str)

thanks
Andrew Poulos
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
VetaMcRae
Top