Expert help needed: external document through a fame

Discussion in 'JavaScript' started by immortalus, Jun 2, 2007.

  1. #1
    Hi,
    I'm on a verge of desperation... I've spent lots of time coding to find out I was in "Access violation" :(

    I've made a really nice calculator for a web game.
    The web game has a sort of a marketplace where you could buy things, but it's built in a very uncomfortable way.

    On my site, I've added a calculator for this marketplace which would make it a lot more comfortable.
    The game is opened in a frame, and at the end of the calculation the user would be able to simply move all the results into the appropriate fields in the game frame.
    I used:
    parent.FrameName.forms.InputName.value = document.MyForm.InputName.value

    <i is a calculated value, since the game has no names to the forms..>

    Since while developing I used a page with copied source, All worked well, but when I ran the code online, I found out that I get "Access Denied" error when attempting to write into the external document :eek:

    Since the game checks for referrer, I have no idea what to do...

    Please help me around this thing :(
     
    immortalus, Jun 2, 2007 IP
  2. wing

    wing Active Member

    Messages:
    210
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    58
    #2
    Are you trying to write to a file on another server?
     
    wing, Jun 2, 2007 IP
  3. immortalus

    immortalus Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    No, I'm trying to make JS fill up a form that is on a page on a different server.
    The page is loaded in a frame on my site...
    The problem is I found that there's this thing called "Same-Origin Policy" JS sticks to, and I need a workaround for it...
    If you know a way, I'd be most grateful!
     
    immortalus, Jun 3, 2007 IP
  4. it career

    it career Notable Member

    Messages:
    3,562
    Likes Received:
    155
    Best Answers:
    0
    Trophy Points:
    270
    #4


    forms.InputName check the variable name (it is case sensitive)
     
    it career, Jun 3, 2007 IP
  5. immortalus

    immortalus Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Look one reply above..
    I found the name to my problem: it's called "Same-Origin Policy".
    It means that no access will be granted to a document which is stored on a server that is not the server the JS code is located on, And/Or a document that has been loaded using a different protocol then the one the JS code is located on.

    An example:
    My site is: www.anExampleHost.com/dir/page.htm
    On page.htm there are 2 frames:
    frame1: code.htm
    frame2: http://www.aDifferentServer.com/path/page.html

    code.htm can't access page.html since it's summoned from a different host.

    Example2:
    My site is: http://www.anExampleHost.com/dir/page.htm
    On page.htm there are 2 frames:
    frame1: code.htm
    frame2: https://anExampleHost.com/dir/target.html

    code.htm can't access target.html since it's loaded via different protocol:
    http != https (secure http)

    My problem is of the first example.

    My question is: "Is there a way around it? Can I somehow bypass the Same-Origin Policy" ?
     
    immortalus, Jun 3, 2007 IP
  6. wing

    wing Active Member

    Messages:
    210
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    58
    #6
    Using only javascript: no you can't, because it's cross site scripting.

    The workaround I think could be to extend your javascript with serverside coding.

    Something like sending a string+session_id+some unique key by firing off a regular post/get to the other site and on the receiving end the data sent would have to be processed and displayed making a call back to your end to trigger a refresh of the displayed data.

    I.E it would be necessary to establish this "communication pipe" on both ends.

    Just my $0.02 :)
     
    wing, Jun 3, 2007 IP