We have some functionality for exporting data to an excel file.
When the 'export' button is clicked, some client-side javascript is called, firstly checking the client browser version, and based on this, deciding which way to render the excel document.
It is working in Chrome & Firefox & IE11 when tested locally.
However, when I remotely test using a windows 10 machine running Edge browser, the excel is not rendered.
I might add that my local machine is a Win7 machine and Im running VS2012 and IE11. The remote machine is Win10 with Edge, hence the need to test remotely.
I've tried the emulation in IE11 F12 dev tools but cant replicate the Edge error there.
An error of 'undefined or null reference' is thrown for 'open' when using the following code:
excelIFrame.document.open("txt/html", "replace");
excelIFrame.document.write(sHTML);
excelIFrame.document.close();
excelIFrame.focus();
excelIFrame.document.execCommand("SaveAs", true, "Spreadsheet.xls");
The iframe exists in the html and is not added dynamically.
<iframe id="excelIFrame" style="display:none"></iframe>
I have tried the following possible solutions to get this working, to no avail -
Possible Solution 1: Same 'undefined or null reference error when assigning the document to a temp var
var doc = excelIFrame.document;
doc.open("txt/html", "replace");
doc.write(sHTML);
doc.close();
doc.focus();
doc.execCommand("SaveAs", true, "Spreadsheet.xls");
Possible Solution 2: Using the contentWindow property of the iFrame. No error thrown, it just opens 'about:blank' containing no content.
excelIFrame.contentWindow.contents = sHTML;
excelIFrame.src = 'javascript:window["contents"]';
Totally at a loss with this at this stage.
The page is an angularJS web page.
From reading up on it, I'm aware the document.open is problematic in edge when using iframes. But the following link document.open fails in an iframe I felt would solve the problem.
Any thoughts or suggestions greatly appreciated.
This may be helpful to others who are searching for it.
//For Edge browser ….. U have to write separate logic for each browser
if (ua.match(/Edge/)){
var blob = new Blob([sHTML], {type: 'data:application/vnd.ms-excel'});
window.navigator.msSaveBlob(blob, "P2P_Report_"+new Date().getTime()+".xls");
}
Related
I have a local IIS site where i developed some code with PDF.js. There it worked fine to load a specific PDF and read the text contents from it.
Then I copied everything to the a library in a SharePoint Server (thats the only difference, IIS vs SharePoint) and changed all references. The code does not throw any Errors, with debugging level info it just prints
Info: Cannot use postMessage Transfers
to the console. Adding a console.log line into the PDF.js catch block of the promise did not result in any new information. It doesn't even get to the first logging inside the then:
var pdfobj = PDFJS.getDocument(docPath);
pdfobj.then(function (pdf) {
console.log(pdf);
any ideas?
EDITS: Updated from PDF.JS 1.1 to 1.2
There are not many error logs in PDF.js. I accidently hardcoded a wrong URL where even the server is non existent... and no error log, not even the then(...).catch(...) is called?
It is working now in Firefox but not in IE and I cannot see any reason for this. The Info message about Cannot use postMessage Transfers is also only displayed in IE (using IE 11).
It does work now. I am not sure what I did to fix it, but I will update this answer when I know. I think it has something to do with the directory structure of the PDF.js files. Previously I just uploaded all JS files (there were no errors though).
Still there is no exception handling when the PDF does not exist.
I've been trying to edit some pages as local htm files on my computer, but I've run into this problem where functions using the contentWindow property don't work when the parent page and the page within the iframe are local files. When all the pages are uploaded the exact same codes work fine, but not as local files. It's only in Chrome and Opera that I've had this problem. In Firefox and Safari and even Internet Explorer contentWindow works fine with local files.
This is very annoying because I've got a dynamic iframe resize in the page I'm working on and I don't want to have to reupload all the pages every time I want to test them in Chrome which is my main browser.
Is there some sort of security setting in Chrome (and Opera) that's causing this problem, and if so can it be disabled?
The code is just:
function resizeIframe(iframeName) {
document.getElementById(iframeName).style.height = '1000px';
newHeight = document.getElementById(iframeName).contentWindow.document.body.scrollHeight;
setTimeout(function () {
document.getElementById(iframeName).style.height = newHeight + 'px';
}, 10);
}
As it turns out, it is a security thing, but there's no way to simply turn it off from the settings menu. The only way (so far as I've found) to turn it off (in windows) is to open Chrome from the command prompt window by typing the file path and adding --allow-file-access-from-files to the command line. This also works for Opera.
Unfortunately this doesn't turn it off permanently so you have to open the browser this way every time you want to test a page that uses the contentWindow property. This works out okay when I'm using Chrome because I keep it open on my computer all the time anyway, but it's a little annoying when I want to test something in Opera. Maybe somebody else will post a way of making it permanent, but for now this will have to do.
Sources:
Is it likely that future releases of Chrome support contentWindow/contentDocument when iFrame loads a local html file from local html file?
http://www.chrome-allow-file-access-from-file.com/
I am creating a small javascript simulation of a java-based (JSF) server. The bootstrap javascript file will download and parse a bunch of files using AJAX, and then generate a large HTML string. This HTML string is a full HTML document - it has a doctype, head, script includes, inline scripts, body, etc.
The reason I do not want to use the real JSF back-end is because I would like to be able to have a pure UI environment to test my code without any java/oracle server slowing me down.
I want to share my code (in a .zip file for example) with anyone and they should be able to open the page (with a small loading screen while the AJAX calls are made) in any browser without some server already installed on their machine.
The answer to that question led me to explore more - now I've run into a different error but I cannot seem to explain it.
Fiddle #1 : This one attempts to put the HTML into an iframe using the iframe's document.write. In this HTML there is a script that pushes a new history state history.pushState(null, null, hash)
Fiddle #2 : This one attempts to put the HTML into the iframe, but this time it just uses location.hash = hash
Both fiddles seem to work fine in Chrome and Safari and IE 9 - but Firefox gives the following error:
NS_ERROR_FAILURE: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMHistory.pushState]
I don't understand this error - if you do this same code history.pushState(null,null,"#test") on any page in firefox using the javascript console in FireBug it works fine - but in this particular situation it doesn't work.
I also tried to perform document.open(); document.write(html); document.close() on the document in the current page (instead of creating an iframe), but the same problem happened - only this time if I put break points in firebug into javascript code inserted in the HTML fragment, the breakpoints don't work which would mean I could no longer debug anything in firefox. At least with the iframe approach, the breakpoints work.
Can anyone shed some light into this problem?
Here is another related question that I asked yesterday which lead to finding this error: Firefox Fail - After using document.write and update to location.hash causes page refresh
You can put this code
history.pushState(null,null,"#test")
before
document.open();
document.write(html);
document.close();
I have run into a similar issue trying to open an Ember app using history.pushState (Ember Router location: 'history' method of routing) inside an iframe. It appears the issue only occurs when doing a hard refresh (cmd + shift + r on Mac or ctrl + f5 on Windows) in Firefox. The issue only occurs for me in FireFox, works fine in Chrome and Safari with similar hard refresh.
The issue does not occur for me when navigating to the page for the first time or when normally refreshing the page (cmd + r Mac, f5 Windows). I have found many seemingly related on Bugzilla for Mozilla but many are close. This one seems to represent the same issue I am having and is still open as of current versions of Firefox (v37.0.1 at time of writing).
https://bugzilla.mozilla.org/show_bug.cgi?id=1003100
I'm currently recording Web Performance Tests using Visual Studio 2010.
The recorder is working fine except for a javascript that is triggered in a popup (fckEditor file manager).
When editing HTML content in fckEditor, we can add an hyperlink. Clicking on the link tool open a popup with a file browser on the server. All files are displayed as hyperlink with a onsubmit event:
OpenFile(fileUrl); return false;
The OpenFile function fails at the following line:
window.top.opener.SetUrl( fileUrl ) ;
The following error is thrown:
SCRIPT5007: Unable to get value of the property 'SetUrl': object is
null or undefined frmresourceslist.html, line 92 character 2
This error only appears when recording with MS Recorder. Following the exact same steps on IE without the Recorder on is working fine.
Does anyone had the same type of issue?
As per MSDN:
A downside to this recording method is that it can fail to record
requests made by JavaScript (for example, on AJAX sites), ActiveX
controls, and some types of pop-up windows, since Internet Explorer
does not always raise the necessary events. In most cases, these
problems can be solved by manually adding the missed requests back
into the Web test, as described later in this document.
http://msdn.microsoft.com/en-us/library/ms364082(v=vs.80).aspx
Even if this documentation is intended to Visual Studio 2005, I believe that it is still valid for VS 2010.
you can solve this by making parse dependent Requests property = false for every single request and
you can make some custom web plugin test so you can generalize this property for all the requests
I get the following error in Chrome's developer tools window when I try to set a cookie using this jQuery plugin:
Uncaught Error: SECURITY_ERR: DOM Exception 18
What does this error mean and how can I fix it? I get the same error when I use this jQuery plugin.
You're most likely using this on a local file over the file:// URI scheme, which cannot have cookies set. Put it on a local server so you can use http://localhost.
I also had this issue while developping on HTML5 in local.
I had issues with images and getImageData function.
Finally, I discovered one can launch chrome with the --allow-file-access-from-file command switch, that get rid of this protection security.
The only thing is that it makes your browser less safe, and you can't have one chrome instance with the flag on and another without the flag.
You can also "fix" this by replacing the image with its inline Base64 representation:
img.src= "data:image/gif;base64,R0lGODlhCwALAIAAAAAA3pn/ZiH5BAEAAAEALAAAAAALAAsAAAIUhA+hkcuO4lmNVindo7qyrIXiGBYAOw==";
Useful, when you do not intend to publish the page on the web, but instead use it on local machines only.
Faced with the same situation playing with Javascript webworkers. Unfortunately Chrome doesn't allow to access javascript workers stored in a local file.
One kind of workaround below using a local storage is to running Chrome with --allow-file-access-from-files (with s at the end), but only one instance of Chrome is allowed, which is not too convenient for me. For this reason i'm using Chrome Canary, with file access allowed.
BTW in Firefox there is no such an issue.
This error pops up, if you try to create a web worker with data URI scheme.
var w = new Worker('data:text/javascript;charset=utf-8,onmessage%20%3D%20function()%20%7B%20postMessage(%22pong%22)%3B%20%7D'); w.postMessage('ping');
It's not allowed according to the standard: http://www.whatwg.org/specs/web-apps/current-work/multipage/workers.html#dom-worker
I had this issue when using the history API.
window.history.pushState(null, null, URL);
Even with a local server (localhost), you want to add 'http://' to your URL so that you have something similar to:
http://localhost...
I wasn't completely happy by the --allow-file-access-from-files solution, because I'm using Chrome as my primary browser, and wasn't really happy with this breach I was opening.
Now I'm using Canary ( the chrome beta version ) for my development with the flag on.
And the mere Chrome version for my real blogging : the two browser don't share the flag !
One can also receive this error if using the new (so far webkit only) notification feature before getting permission.
First run:
<!-- Get permission -->
<button onclick="webkitNotifications.requestPermission();">Enable Notifications</button>
Later run:
// Display Notification:
window.webkitNotifications.createNotification('image', 'Title', 'Body').show();
The request permission functions needs to be triggered from an event caused by the user, otherwise it won't be displayed.
I was been getting that error in mobile safari when using ASP.NET MVC to return a FileResult with the overload that returns a file with a different file name than the original. So,
return File(returnFilePath, contentType, fileName);
would give the error in mobile safari, where as
return File(returnFilePath, contentType);
would not.
I don't even remember why I thought what I was doing was a good idea. Trying to be clever I guess.