Forum Moderators: open
For example, using php, clicking a link with a "test.php" url may results in this php output:
==================
header("Content-Type: text/plain");
header("Content-disposition: attachment; filename=test.txt");
echo "the content";
exit();
This would results in a "save file as" dialog box to appear and the page would stay where it is: no new page would be loaded.
I wonder if there is a way to output something, some headers, that would prevent the location of the page to change as well, but without poping any dialog box? Some kind of "request cancellation" we might say.
Is there a way, for example, to return some kind of empty "text/javascript" content, which would be "interpreted" without the location of the page to change?
Any idea?
Thanks in advance!
That would pose a huge security risk, as you would essentially be viewing a page that was different from the URL.
If there was a way to send some kind of "cancel request" headers, the url would still reflects the page loaded, since the url of the clicked link wouldn't even be shown in the url bar. And anyway, we all know it's possible to do anything to the page without chaging its url, if we use ajax.
Some ideas (didn't try them):
- output attachment headers but close the dialog box immediatly using javascript (is it possible?)
- output an invalid attachment that wouldn't even triggers the "save as" dialog box
- output some css or js content in a way the browser would interprets them instead of trying to open/save them.
Not necessarily. When a "save as" dialog box pops, for example, there is no "other page viewed".
1. user clicks link
2. browser sends HTTP request to server
3. server sends an HTTP response
4. browser interprets response and does appropriate action based on the HTTP headers and content returned (for example, show a web page, show a 404 error, provide a "save" dialog, pass the content to an appropriate handler for that mime type, etc.
Are there any HTTP headers that would cause the content to be displayed without changing the URL? Again, I don't believe so, as that would be a security risk (it would allow real sites to be spoofed). Your only option would be to use AJAX to send a request to the server, and then replace the contents of the current page with the results.
I don't want "the content to be displayed without changing the URL". I just want the HTTP request to reach the server without changing the URL. No content to show or to display.
I know everything you said! I'm looking for some kind of secret headers that would cause the browser to do nothing at all! To discard the HTTP response or to react to it, but invisibly.
By the way, I'm only asking this question by technical curiosity! If I needed to make an invisible request to the server, in real life, I would simply use any ajax method.
I'm looking for some kind of secret headers that would cause the browser to do nothing at all!
Then why return anything? Like this
exit();
I may be missing something here but if you want to return something but have the browser do nothing wouldn't that be the same as not returning a response at all? I mean save yourself a step, don't return anything and the browser will happily do nothing.
Obviously my suggestion would cause a browser timeout waiting for a response.
I really don't see a way of doing this other than with Ajax, unless there is some secret header that we don't know about that tells the browser not to expect a response.
Of course ajax would work. But this is not my question.
I don't think the way to accomplish what I'm trying to do (again just for fun) is to tell the browser it shouldn't expect any response. Because this would probably leads to a blank page, with the new url in the url bar (as with "exit()").
I think that if there is a way to do it, it will be by sending some kind of headers/content that would not be handled by the browser as "content to display".
I think that if there is a way to do it, it will be by sending some kind of headers/content that would not be handled by the browser as "content to display"
Yes but in this case the browser would ask the user what it is to do with it as it would with any content it doesn't know how to handle.
If the user set up his browser to "Always do nothing" when you encounter this file/content type then maybe... but you would have to have this set up on every client machine that used the site and that isn't realistic unless it was an Intranet and the only machines looking at it were office workstations that you could set up in such a way.
Now I see you understand what I'm really trying to find: some headers/content that would not be seen as "content to display" but that wouldn't trigger a "what do you want me to do with this content?" dialog box either! And without having to configure the browser so it automatically does something (or does nothing) with those particular headers/content either!
I'll repeat my main ideas:
- Finding a way to output javascript (text/javascript), or css (text/css), in a way the browser automatically interprets it.
- Finding a way to output an invalid attachment, in a way the browser wouldn't even pops a "save as" dialog box.
In test.php...
header("HTTP/1.1 204 No Content");
exit; [w3.org...]