Kilka informacji od 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.
informacji od Mozilli
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
Więc odpowiedź brzmi
- Więc, jeżeli protokół i nazwa hosta i port mecz dla wszystkich przeglądarek ale IE, to w tej samej domenie
- Jeżeli protokół i nazwa hosta mecz dla IE, to ta sama domena
przeciwnym razie są ograniczone.
EDIT - realna odpowiedź
window.open('javascript:doFunction()')
nic nie robić oprócz otworzyć nowe puste okno, które nie jest do niczego, bo doFunction
nie jest zdefiniowana. Należy go zdefiniować w tym samym oknie.
Sidenote mogę zrobić żądania XHR tego samego pochodzenia przez wstrzykiwanie ajax do adresu URL bezpośrednio, ale nadal jest podatny na politykę tej samej domeny.
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"); ');
Nie powiedzie się w przeglądarce Firefox. I jeszcze tego nie testowałem w MSIE.Ale
Testy:
(niewydolność) Chrome 7 (konsola) z 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
(sukces) Chrome 7 (konsola) z http://stackoverflow.com:80
>>> x = window.open('http://stackoverflow.com', 'fds', 'width=200, height=300')
>>> x.document.body.innerHTML='test';
"test"
(awaria) Firefox 3.6 (konsola) z 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>.
(sukcesu) Firefox 3.6 (konsoli) z http://stackoverflow.com:80
>>> x = window.open('http://stackoverflow.com', 'fds', 'width=200, height=300')
>>> x.document.body.innerHTML='test';
"test"
(awarii) Firefox 3.6 (konsoli) z http://stackoverflow.com:80
$.ajax({
url:'http://bing.com',
success:function(data) {
alert(data) // blank alert
}
})
(sukces) Firefox 3.6 (konsola) z http://stackoverflow.com:80
$.ajax({
url:'http://stackoverflow.com',
success:function(data) {
alert(data) // success
}
})
Dobre pytanie! Jednak wiesz, że będziesz musiał zaimportować całkiem sporo, aby uruchomić 'someAjaxFunction()', ponieważ nie będziesz miał dostępnych bibliotek okna otwierającego? W każdym razie zakładam, że lokalizacja skryptu dla celów sprawdzania tego samego pochodzenia jest "niezdefiniowana". –
Co to ma znaczyć? Czy chcesz, aby wywołanie AJAX pobierało adres URL dla nowego okna? A może wywołanie AJAX ma na celu pobranie nowej zawartości okna? Jeśli to drugie, to nie ma większego sensu, chyba że to, co robisz, to POST. – Pointy
Należy również zauważyć, że naprawdę ** nie ma takiej rzeczy ** jako adresu URL "javascript:". – Pointy