Currently some guys programmed this in a HTML page:
<script>
location='http://example.com/downloadable.zip';
</script>
They want to redirect the user to another page once the file has started downloading. I can only modify this page but not the destination page.
What would be a good and clean javascript solution for making a user download the file and once he had accepted (or rejected) it, redirect him to another location? The solution may be jQuery code
NOTE: The downloading and redirection must be done automatically when accessing the page
Perhaps setup a link that calls a function. The function would in turn then send the download link, and then redirect.
This is just a guess based upon your description, as I don't know the full general setup, but it's what I would do going on what I know.
This seems like a hack. Have you tried an HTML meta tag with refresh? Also, you can add a link if the download fails.
Related
I would like to know, is there a way to edit a Javascript file or a specific page, on any website, and refresh this page and show my changes?
For example, there is a website: http://example.com.
Many files are requested including a Javascript file:
http://example.com/assets/app.js
Can I modify this app.js file, and show my modifications when updating the page or is this not possible?
For example, save the file my cache? Or something like that?
and Thanks.
Normally speaking, you can't directly modify the files like assets/app.js, etc, since they are stored and read from the backend server of http://example.com.
However, you can still make custom changes to some specific pages/websites by scripts/styles injecting.
I think you might be interested in some browser plugins/scripts like:
Tampermonkey: https://www.tampermonkey.net/, Greasyfork: https://greasyfork.org/en, Stylish: https://userstyles.org and so on ... :)
I have two websites www.mywebsite.com and www.otherwebsite.com. I use iframe to redirect mywebsite.com to otherwebsite.com. Is there a to change the path of url on page change. For example when a link otherwebsite.com/contact.html is clicked the frame adds /contact.html to mywebsite.com making it www.mywebsite.com/contact.html. I tried adding the code below to the page but it doesn't seem to work on the frame.
history.pushState(null, "A new title!", "contact.html")
what you trying to do is not possible without a server side language (for example php).
this is because you need to define filename as a variable for your frame to load it with another site.
but you can do it at some static way like making the real contact.html and code it with a frame that shows contact.html for another side ... but i dont think that would be a dynamic way without any server side coding...
I was wondering if i can to make url such like this:
http://www.google.com/index.php?id=mycustomsearch,javascript:onload=initfunction1();
To make myself clear i'll explain.
I want to modify the link to make a javascript action.
To be able to give the same exact page but triger every time another function based on the link.
I wrote [,] just for demonstration. I dunno if there is a way to do it.
Okay do not approach the problem via a query string in the URL. This is will open your site up to XSS attacks. http://en.wikipedia.org/wiki/Cross-site_scripting
If you wanted to run a JavaScript function once the page has loaded use JavaScript or jQuery and do something like:
$(document).ready(function() {
YourFunction();
});
function YourFunction() {
alert('Your function logic');
}
You could filter the function name via the query string, sure, however do not embed JavaScript into the URL.
http://www.yoursite.com/?function=YourFunction
Without using something like greasemonkey installed on your machine, no, you can't (and shouldn't) do this. If the URL is on one of your domains, you can embed the script in your page, if it's someone else's... no.
I've been using the Microsoft Technet site and you can download the ISO files by clicking a link on the page. The element is like this:
<a href="javascript:void(0)" onmouseout="HideToolTip()"
onmouseover="ShowToolTip(event,'Click here to download.')"
onclick="javascript:RunDownload('39010^313^164',event)"
class="detailsLink">Download</a>
I wasn't able to find the RunDownload() method in the scripts. And I wondered what it is likely to do. I mean usually when I provide a link for someone to download I provide an anchor to it:
download
But this is working differently what is the script doing? Because even when I ran 'Fiddler' I wasn't able to see the actual download location.
there's no such thing as a "javascript download" link. Javascript can open a new window, or simulate a click on a link.
What you have to find is which url the function triggered by this click will lead to.
here's an example of how to do it:
Suppose we have a:
<a id="download">download Here ยงยงยง</a>
then this jQuery code:
$('#download').click( function() {
window.location.href = 'http://example.org/download/ISO.ISO';
} );
will redirect to the URL http://example.org/download/ISO.ISO. Whether this url starts a download or not depends on HTTP headers and your browser, not on what javascript do.
Download location can be a url-rewritten path. This mean that maybe some parameters are given with HTTP Post and some HTTP handler in the Web server or web application may be getting some arguments from the HTTP request and write file bytes to an HTTP response, which absolutely hides where the file is located in the actual server's file system.
Maybe this is what's behind the scenes and prevents you to know the file location.
For example, we can have this:
http://mypage.com/downloads/1223893893
And you requested an executable like "whatever.exe" for downloading it to your hard disk. Where's the "http:/mypage.com/downloads/whatever.exe"? Actually, it doesn't exist. It's a byte array saved in a long database in some record, and "mypage" web application handles a request for a file that's identified as "1223893893" which can be a combination of an identifier, date time or whichever argument.
What I think the function RunDownload might do is that it might inform the server using get request to the server that another download is about to happen , or it might need to run the download background by setting the target attribute to an iframe so the user won't need to open another tab and download the file on the same page.
Download
JS
var runDownload=function(){
e.preventDefault();
increaseDownloadCountOnTheServer(location);
window.location.href="filelocation.exe";
}
I download via jQuery AJAX a whole html webpage. I want to replace the content of the current page with the one downloaded via ajax. I do it with document.write(). It doesn't work correctly because whenever I try to modify the hash, the webpage is reloaded.
I know in IE it it necessary an iframe, but that is not the problem, because I use jQuery History plugin. The problem is due to the use of document.write(), but I don't know why.
Update:
index.php -> main entry point, which downloads JS code to parse URL after hash and invoke request.php.
request.php -> request entry point. It returns the webpage.
It works OK when I simulate a direct request to request.php and the downloaded webpage updates the hash.
It doesn't work (in FFox only) when I simulate a original request to index.php, which downloads the webpage via request.php and the downloaded page modifies the hash.
I use document.write() to write the content of the webpage to the current window. So the problem is about the modification of the hash in a document "being written".
don't use document.write().
instead use $('your selector').html(your_html_fetched_via_ajax);
I thinkg that you can't modify the whole html object because it means erasing the reference to the javascript script tag. I would say your best bet is to either just link to the request.php page or just change the body tag
$('body').html(response_html);
And I agree with harshath.jr, don't use document.write().
The individuals pointing you towards an iframe are correct. Add the iframe, and simply set the src attribute to the page you're fetching...you won't even need request.php.
If you really want to try to load in the html without an iframe, you'd have the parse out the elements in the head and add them to your documents , and also parse the contents of the and add them to the current pages body. Its not guaranteed to display correctly, though. I think an iframe is really what you're looking for.