Is there any way to set the src attribute of an iframe without the iframe generating an http request? If not, is there a way to format the request headers before the request is sent?
edit: I just need the src to match the path of a cookie, but I don't ever want that cookie sent to the server. See my comments on this question.
No there is not a way to do this.
Related
I want to make a client-side application that loads JavaScript files using only script-tags, (and not fetch, due to cross-origin concerns), but I was wondering if its possible to somehow set the custom request headers in the script tag, such that I can receive only part of a file (the equivalent to sending the range: bytes 10-40 header), or other custom headers the server may request?
No, that's not possible. A script tag will create a regular HTTP GET request without any means to control the headers.
I need to access a page on another domain, which returns as response a JSON array:
[{"name":"value","x":"y"},{"name":"value","x":"y"}]
Due to the cross-origin rule, I can't get this data through an XMLHttpRequest. Apparently I have to use a JSONP-like procedure:
Add script element to the page's body, with the src attribute poiting to the page
The browser does the HTTP request and gets the data
I can not edit the remote page/the response. The remote page is not meant to be accessed that way (so I can't use a JSONP callback parameter).
The remote page also requires the use of a specific cookie.
How can I access the data that has been just retrieved?
That's exactly the case the same origin policy exists for. Any possible solution would mean a security hole. If the data server unable to wrap it in your callback function, you have to proxy this through your own server-side app.
I need to be able to read the request headers coming from a redirect from a naked domain:
http://mydomain.com
to
http://www.mydomain.com/index.html
I need index.html to be able to parse any original request path and queries, how can I do that?
E.g
From naked domain: http://mydomain.com/abc to http://www.mydomain.com/index.html and then index.html will get the abc path request.
The question is how to be able to achieve this?
A similar question: Using DNS to redirect to another URL with a path
use document properties to check and reditect
for others questions use navigator roperties
Get referrer use = document.referrer or document.URL
Look : http://www.w3schools.com/jsref/dom_obj_document.asp
In apache the best solution is control that with .httaccess
I want to be able, using javascript, to reload the currently loaded resource, but customising some header variables, before doing so.
This method is needed/should be used in 2 real cases:
As a way, to handle login via real HTTP-login, which means reloading the resource with attached authentication data
To get different media-type representations of the same resource, which means modifying the accept header, before re-sending the request.
As I would need to leave any other header fields unchanged, as the browser would send it natively, I cannot simply construct my own XMLHttpRequest, using the document.URL value. Rather I would need to get hold of a XMLHttpRequest representation of the request, the browser sent for the current resource.
Is there a way to accomplish that in JS? Preferably using pure JS without any jQuery magic.
If it was loaded via GET, you can just create an XMLHttpRequest and use document.location.href as the URL.
The browser will specify the usual cookie headers, so your request headers should be largely the same unless the GET changed cookies in non-idempotent ways.
If the current resource was loaded via POST, then you are out of luck. The POST body of the current resource is not available to JavaScript so unless you would need some other way to get it or infer it from page content.
Is it possible to load for example google.com to a javascript variable?
var html = "the html of google.com"
Is this possible?
Update:
What about in an air application?
Not unless you send the source from the server.
From javascript, it will violate the Same Origin Policy. You can send the request, and you'll get a response, but the response will be empty.
If it's a page in the same domain you're in, then yes. Otherwise, not without some special URL provided by the target domain that sends you pages based on some form of special request.
You can always have your own server fetch the page and forward it to your client.