new window - can't read property

G

Grzegorz ¦lusarek

hello. I've code like this:

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

Permission denied to get property Window.innerWidth
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.getElementById('canvas')
Permission denied to call method HTMLDocument.getElementById

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

what i doing wrong?
Any help will be appreciated.
 
P

Peroli

Hi Grzegorz Slusarek,

Grzegorz said:
hello. I've code like this:

var x =window.open('http://localhost/canvas.html','myokno')
var w =x.width
Permission denied to get property Window.width
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'.
var w =x.innerWidth

Permission denied to get property Window.innerWidth
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
wrong.... use 'x' as you have done below.
var canvas = x.document.getElementById('canvas')
Permission denied to call method HTMLDocument.getElementById

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

what i doing wrong?
Any help will be appreciated.

-- Peroli Sivaprakasam
 
G

Gérard Talbot

Grzegorz ¦lusarek a écrit :
hello. I've code like this:

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

Permission denied to get property Window.innerWidth
why i can get properties of new created window???

Read the WindowObjectReference definition
http://developer.mozilla.org/en/docs/DOM:window.open#Return_value_and_parameters
and then the last question of the FAQ
http://developer.mozilla.org/en/docs/DOM:window.open#FAQ
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

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.
var canvas = x.document.getElementById('canvas')
Permission denied to call method HTMLDocument.getElementById

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

what i doing wrong?
Any help will be appreciated.

There are examples and best practices at this page:

http://developer.mozilla.org/en/docs/DOM:window.open

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
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top