This question already has answers here:
Get protocol, domain, and port from URL
(19 answers)
Closed 5 years ago.
I'm running the development server on localhost:8000. Can document.domain include a port number, e.g., document.domain = 'localhost:8000'? I seem to be getting an error saying localhost:8000 cannot be parsed properly.
No. The document.domain includes only the host name.
document.domain
Gets/sets the domain portion of the origin of the current document, as used by the same origin policy.
Alternatively, location.port gets you the port of the domain.
Related
This question already has answers here:
Cross domain iframe issue
(5 answers)
Closed 5 years ago.
My webpage(wp1) has an iframe. The source of the iframe is another webpage(wp2). I have some javascript functions on wp1 which try to manipulate the contents of wp2. However , the browser gives " Blocked a frame with origin "null" from accessing a cross-origin frame." How can i get around this?
According to the MDN page about postMessage, if your parent and child domains differ only by a subdomain (e.g example.com and subdomain.example.com), you can set document.domain to the same value on both pages and it should be enough to get it to work.
Accepted value for document.domain is that of the superdomain (example.com = ok, subdomain.example.com = nope), according to Same Origin Policy.
This question already has answers here:
How to allow http content within an iframe on a https site
(10 answers)
Closed 5 years ago.
This code works in my chrome but not in fileserver.
<body>
<div>
<iframe src="http://www.yunoworldtech.com/" height="710px" width="99%">
</iframe>
</div></body>
The above is the link which I included in the iframe(code). I got successful implementation in local machine but on the file server, i am not able to load it.
File server link
Help is appreciated.
Failed to execute 'postMessage' on 'DOMWindow': The target origin
provided ('https://hootsuite.com') does not match the recipient
window's origin ('https://dinuduke.000webhostapp.com').
You got the CORS problem. You request a resource from other domain and the other domain by default not authorize such request. More info here
This question already has answers here:
XMLHttpRequest cannot load XXX No 'Access-Control-Allow-Origin' header
(11 answers)
Closed 6 years ago.
This confuses me a lot. Let's say I have 2 tabs open in my browser, one on http://aaa.com and another on http://bbb.com.
Let's say I make a request
$ajax({
method : 'POST',
url : 'http://aaa.com/SomeAction',
...
});
from the JavaScript console of my browser. The way I understand cross-origin policy is that the server only allows that request to happen if the JS console I typed it into was the one in the tab for http://aaa.com. But how does the server know that? Does my browser send it a header that tells it where the request is coming from?
is that the server only allows that request to happen if the JS
console I typed it into was the one in the tab for http://aaa.com
Not true.
Nothing stops example.com from sending an AJAX request to example.org. The Same Origin Policy however will prevent example.com from reading the response returned.
The Same Origin Policy is enforced in the client-side browser, not on the server.
This question already has answers here:
Origin null is not allowed by Access-Control-Allow-Origin
(8 answers)
Closed 8 years ago.
How to avoid "Request header field Authorization is not allowed by Access-Control-Allow-Headers" error running JavaScript from local drive?
So I cannot modify server headers as there is no server.
Thank you.
That is not duplicate as solution offered at 'Origin null is not allowed by Access-Control-Allow-Origin' does not work, you can read about it there.
No. You will need a server like Mongoose (very simple download and run in your root). A very easy fix.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
XmlHttpRequest error: Origin null is not allowed by Access-Control-Allow-Origin
XMLHttpRequest cannot load file://… Origin null is not allowed by Access-Control-Allow-Origin
I am trying to open my JSON file such as:
jQuery.getJSON('../data/json/en/nodesData.json',
function(data){
jQuery.each(data, function(){
//do something...
})
})
this yields the following error in Chrome:
XMLHttpRequest cannot load file:///C:/URL/data/json/en/nodesData.json. Origin null is not allowed by Access-Control-Allow-Origin
what's problem? How can I retrieve my json?
You really should be running a local server like Apache or IIS to run HTML/JavaScript code so you do not run into these restrictions.
You can start the browser up with the flag --allow-file-access-from-files which removes the restriction.
For security reasons, you cannot make AJAX calls to your local file system. Some browsers allow this, but others don't. Chrome has a flag that enables this, but it's off by default.
Take a look into Same Origin Policy.
You cannot load the file because technically it is located in another domain. You need to call it like localhost/<Path>/nodesData.json.