alcune informazioni da Google: http://code.google.com/p/browsersec/wiki/Part2#Same-origin_policy_for_DOM_access
With no additional qualifiers, the term "same-origin policy" most commonly refers to a mechanism that governs the ability for JavaScript and other scripting languages to access DOM properties and methods across domains (reference). In essence, the model boils down to this three-step decision process:
If protocol, host name, and - for browsers other than Microsoft Internet Explorer - port number for two interacting pages match, access is granted with no further checks. Any page may set document.domain parameter to a right-hand, fully-qualified fragment of its current host name (e.g., foo.bar.example.com may set it to example.com, but not ample.com). If two pages explicitly and mutually set their respective document.domain parameters to the same value, and the remaining same-origin checks are satisfied, access is granted. If neither of the above conditions is satisfied, access is denied.
informazioni da Mozilla
I can not access the properties of the new secondary window. I always get an error in the javascript console saying "Error: uncaught exception: Permission denied to get property . Why is that?
It is because of the cross-domain script security restriction (also referred as the "Same Origin Policy"). A script loaded in a window (or frame) from a distinct origin (domain name) cannot get nor set properties of another window (or frame) or the properties of any of its HTML objects coming from another distinct origin (domain name). Therefore, before executing a script targeting a secondary window, the browser in the main window will verify that the secondary window has the same domain name. More reading on the cross-domain script security restriction: http://www.mozilla.org/projects/secu...me-origin.html
Quindi la tua risposta è
- Quindi, se il protocollo e l'hostname e la porta può competere con tutti i browser, ma IE, è lo stesso dominio
- Se la partita protocollo e l'hostname per IE, è lo stesso dominio
In caso contrario, si sono limitati.
EDIT - vera risposta
window.open('javascript:doFunction()')
non avrebbe fatto altro che aprire una nuova finestra vuota, che non riesce a fare nulla perché doFunction
non è definito. Deve essere definito nella stessa finestra.
Sidenote Posso fare la stessa richiesta xhr di origine iniettando direttamente l'ajax nell'url, ma è comunque suscettibile al criterio dello stesso dominio.
x = window.open('javascript:x = new XMLHttpRequest; x.open("GET", "http://medero.org", false); x.onreadystatechange = function(){ if (x.readyState != 4) { return; }; alert(x); alert(x.responseText);}; try {x.send(null); } catch (e) { alert(e)}; alert("ok"); ');
Fallisce in Firefox. E non l'ho ancora testato in MSIE.Ma
Test:
(guasto) Chrome 7 (console) dal http://stackoverflow.com:80
>>> x = window.open('http://google.com', 'fds', 'width=200, height=300')
>>> x.document.body.innerHTML='test';
TypeError: Cannot read property 'body' of undefined
(successo) Chrome 7 (console) dal http://stackoverflow.com:80
>>> x = window.open('http://stackoverflow.com', 'fds', 'width=200, height=300')
>>> x.document.body.innerHTML='test';
"test"
(fallimento) Firefox 3.6 (console) dal http://stackoverflow.com:80
>>> x = window.open('http://google.com', 'fds', 'width=200, height=300')
>>> x.document.body.innerHTML='test';
Permission denied for <http://stackoverflow.com> to get property Window.document from <http://www.google.com>.
(successo) Firefox 3.6 (console) dal http://stackoverflow.com:80
>>> x = window.open('http://stackoverflow.com', 'fds', 'width=200, height=300')
>>> x.document.body.innerHTML='test';
"test"
(fallimento) Firefox 3.6 (console) da http://stackoverflow.com:80
$.ajax({
url:'http://bing.com',
success:function(data) {
alert(data) // blank alert
}
})
.210
(successo) Firefox 3.6 (console) dal http://stackoverflow.com:80
$.ajax({
url:'http://stackoverflow.com',
success:function(data) {
alert(data) // success
}
})
Bella domanda! Tuttavia, sei consapevole che dovrai importare parecchio per eseguire 'someAjaxFunction()', dato che non avrai a disposizione le librerie della finestra di apertura? Comunque, la mia scommessa è che la posizione della sceneggiatura ai fini del controllo della stessa origine è 'indefinita'. –
Cosa significa questo? Vuoi che la chiamata AJAX recuperi l'URL per la nuova finestra? O la chiamata AJAX dovrebbe recuperare i nuovi contenuti della finestra? In quest'ultimo caso, non ha molto senso a meno che quello che stai facendo sia un POST. – Pointy
Nota anche che non esiste davvero ** niente di simile ** come un URL "javascript:". – Pointy