I am working on a thing where I have an iframe. I want to load a static javascript file to this iframe every time user clicks on a button. The javascript file is located at the server and because this is the static file so I would like it to be downloaded to the client once and every time user clicks on the button it just loads this file into iframe without calling server.
I know AJAX can be used to download this file contents and how to add script tag to the iframe but I am not sure where should I temporarily save the contents and then put the contents back into a file to put that file as script tag into iframe.
You can consider this fiddle.
Have you considered just dumping the data into a cookie?
Related
I have a link on my page which opens up a text file located on the file server. when user clicks on the link it opens up the text file as fetched from the file server but this file gets updated when user refreshes the page. subsequently when user clicks on the same link after refresh to open the file it displays the old file. but when did a ctrl+f5(server cache refresh) on the text file tab it then refreshes and displays the updated file. but end user doesn't do a force refresh. looking to see if there is any work around in JavaScript to do a force refresh of the text file page before loading.
I would suggest monitoring the anchor in the URL to avoid a reload,
that's pretty much the point of using anchors for control-flow. But
still here goes. I'd say the easiest way to force a reload using a
simple anchor-link would be to use
where in place of $random insert a random number (assuming "dummy" is
not interpreted server side). I'm sure there's a way to reload the
page after setting the anchor, but it's probably more difficult then
simply reacting to the anchor being set and do the stuff you need at
that point.
Then again, if you reload the page this way, you can just put
myanchor2 as a query parameter instead, and render your stuff server
side.
Edit
Note that the link above will reload in all circumstances, if you
only need to reload if you're not already on the page, you need to
have the dummy variable be more predictable, like so
I would still recommend just monitoring the hash though.
I have this iframe in a page: document.querySelector("iframe")
It loads a PDF from a server. to avoid calling another request when the user clicks on a button i want to reuse the iframe with the pdf document from this iframe: ex: <iframe src="myAPI/loadPdf.pdf"><iframe>
When a user clicks a button:
var pdfWindow = window.open("");
console.log(document.querySelector("iframe"));
pdfWindow.document.write(document.querySelector("iframe"));
//to avoid making 2 request, use the one that is already loaded
This writes [object HTMLIFrameElement] on the blank page instead of the document
document.write() writes a string to the document. You want to append the iframe node to document.body:
pdfWindow.document.body.appendChild(document.querySelector('iframe'))
But note that when you append the iframe you can see a request for the pdf file in the network panel, however if the browser could cache the file and the cached version is available then the cached version is used and it's not downloaded again. With that said it's actually no use to reuse the iframe since the same thing happens if you just open the window with the url to the pdf file, the cached version will be used if it's available.
I need to save my .php file as an .html for backup with using PHP whenever page called (I am going to use ob_start() for it). But the page content is not static. I am using AJAX to load the content.
That's why view-source: does not show the dynamic data, only chrome inspector show them. But I need to save the page with all elements after page loads. Is it possible or not?
BTW after page loads, there is no any other ajax call (on click or something). Page loads all content on init.
Thanks in advance.
I have a landing page on which there is a form which is filled by user and then it goes to a thank you page (which is another page). On thank you page I simply want to prompt the user for saving a pdf as the thank you page loads. Please note I want the file to be saved/downloaded and not opened on the same tab or another tab in the browser. I have tried multiple solutions but they all seem to open the pdf in the browser itself and not download it. Some of the methods I have tried are meta tag download, page redirect download, iframe download but they all open the pdf in browser itself and not download it. I just want a simple solution for downloading the file and not opening it in the browser. Also the pdf should download automatically without clicking any link or button.
The document.ready event of the thank you page should trigger a local script that runs a server script to download the PDF. Be sure to set the headers as described above. If you try to link directly to the PDF, it'll try to load in the browser.
Alternatively, you could create the PDF in a directory that is already set to only download files by setting the .htaccess file for that directory.
I'm developing a custom module for Drupal dealing with Document Management. At this point, the module loads, you can upload files (via a hidden iframe and some ajax requests), browse directories and set various levels of permissions. And everything works perfectly in Firefox.
Issue:
In IE however, I run into an issue. For some reason when I upload a file the save file dialogue pops up and asks me to download the file I just uploaded. It looks like it's asking me to download it from the web-servers tmp location however, as that seems to be the file-name and such. However, if I hit cancel and refresh the page I can see that the file I uploaded did actually get uploaded to the server.
Here is how the upload process works. Click the upload button. The upload button is the standard file input form element hidden and placed over a styled version of the button. Clicking on this causes the "Choose a file" dialogue to open.
Select a file and click "Open". A modal dialogue pops up asking you for some further information about the file. The modal is part of the same form element but remains invisible until you click Upload button
Clicking save in the modal causes the file to be uploaded. The "action" attribute on the form is pointed to a page and the target is the iframe.
The iFrame is polled a few times every second to see if it's contents have changed. When the file is uploaded a "success" message appears in the iframe. Since it belongs to the same domain, I scrape the content within the iframe.
Once the iFrame says that the file has been uploaded, I use some JS to update the application with the name of the file
Since I can't use Firebug in IE, I have to stick to utilizing Microsofts Web Developer Toolbar, which makes it very hard to figure out if the bolded step is actually occuring. It seems like it should, since the file IS being uploaded. It is just getting interrupted by that file download dialogue.
Since no one seems to have an answer, I'll post the fix I found. I doubt it's perfect, but it's the best solution I could come up with.
It turned out to be an issue with the polling as suspected. The fix ended up being instead of outputting json to the iFrame, just output some JavaScript that calls a function that updates the main window. That simple.