new window - can't read property

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Grzegorz ¦lusarek

    new window - can't read property

    hello. I've code like this:

    var x =window.open('h ttp://localhost/canvas.html','m yokno')
    var w =x.width
    Permission denied to get property Window.width
    var w =x.innerWidth

    Permission denied to get property Window.innerWid th
    why i can get properties of new created window???
    The second problem is much more important:
    i want to get element which id is "canvas" and it is in new window so i do
    like this:

    var canvas = myokno.document .getElementById ('canvas')
    ReferenceError: myokno is not defined
    var canvas = x.document.getE lementById('can vas')
    Permission denied to call method HTMLDocument.ge tElementById

    so i start working on the problem and:
    var can = x.document
    can
    [object HTMLDocument]
    var can2 = can.getElementB yId('canvas')
    Permission denied to call method HTMLDocument.ge tElementById

    what i doing wrong?
    Any help will be appreciated.
  • Peroli

    #2
    Re: new window - can't read property

    Hi Grzegorz Slusarek,

    Grzegorz Slusarek wrote:[color=blue]
    > hello. I've code like this:
    >
    > var x =window.open('h ttp://localhost/canvas.html','m yokno')
    > var w =x.width
    > Permission denied to get property Window.width[/color]
    well, the popup window and the script which initiated it must be in the
    same domain. (for eg). when you have a html file in "c:\sample.htm" ,
    from which you popup "http://localhost/canvas.html", you cannot access
    its properties. Its a security thing that browsers have implemented. So
    copy the sample.htm to your localhost access it as
    'http://localhost/sample.htm'.
    [color=blue]
    > var w =x.innerWidth
    >
    > Permission denied to get property Window.innerWid th
    > why i can get properties of new created window???
    > The second problem is much more important:
    > i want to get element which id is "canvas" and it is in new window so i do
    > like this:
    >
    > var canvas = myokno.document .getElementById ('canvas')
    > ReferenceError: myokno is not defined[/color]
    wrong.... use 'x' as you have done below.
    [color=blue]
    > var canvas = x.document.getE lementById('can vas')
    > Permission denied to call method HTMLDocument.ge tElementById
    >
    > so i start working on the problem and:
    > var can = x.document
    > can
    > [object HTMLDocument]
    > var can2 = can.getElementB yId('canvas')
    > Permission denied to call method HTMLDocument.ge tElementById
    >
    > what i doing wrong?
    > Any help will be appreciated.[/color]

    -- Peroli Sivaprakasam

    Comment

    • Gérard Talbot

      #3
      Re: new window - can't read property

      Grzegorz ¦lusarek a écrit :[color=blue]
      > hello. I've code like this:
      >
      > var x =window.open('h ttp://localhost/canvas.html','m yokno')
      > var w =x.width
      > Permission denied to get property Window.width
      > var w =x.innerWidth
      >
      > Permission denied to get property Window.innerWid th
      > why i can get properties of new created window???[/color]

      Read the WindowObjectRef erence definition
      The open() method of the Window interface loads a specified resource into a new or existing browsing context (that is, a tab, a window, or an iframe) under a specified name.

      and then the last question of the FAQ
      The open() method of the Window interface loads a specified resource into a new or existing browsing context (that is, a tab, a window, or an iframe) under a specified name.

      [color=blue]
      > The second problem is much more important:
      > i want to get element which id is "canvas" and it is in new window so i do
      > like this:
      >
      > var canvas = myokno.document .getElementById ('canvas')
      > ReferenceError: myokno is not defined[/color]

      When you created the window, the returned value was not stored in a
      variable with the identifier "myokno": that's what the error message is
      saying. Without being able to examine your code, it's impossible to
      comment more.
      [color=blue]
      > var canvas = x.document.getE lementById('can vas')
      > Permission denied to call method HTMLDocument.ge tElementById
      >
      > so i start working on the problem and:
      > var can = x.document
      > can
      > [object HTMLDocument]
      > var can2 = can.getElementB yId('canvas')
      > Permission denied to call method HTMLDocument.ge tElementById
      >
      > what i doing wrong?
      > Any help will be appreciated.[/color]

      There are examples and best practices at this page:

      The open() method of the Window interface loads a specified resource into a new or existing browsing context (that is, a tab, a window, or an iframe) under a specified name.


      Basically, you are trying to modify (or set or get) properties or call
      methods from one window to another which do not share the same domain
      name: you can't do that... there are security reasons for this.

      Gérard
      --
      remove blah to email me

      Comment

      Working...