How can i create ActiveX Object in java script using asp.net.what i need requirements to create that ActiveX object if i use any DLL to create that object and how can i create can anyone provide description of to create ActiveX object
My Tried code is:
<script lang="javascript" type="text/javascript">
function getSize()
{
var oas = new ActiveXObject("Scripting.FileSystemObject");
var d = document.getElementById('b').value;
var e = oas.getFile(d);
var f = e.size;
return(f);
}
function checkFileType()
{
var path = document.getElementById('file1').value;
var Index = path.lastIndexOf(".");
var length = path.length;
var filetype = path.substring(Index,length)
if ((filetype == ".doc") ||(filetype == ".pdf") ||(filetype == ".jpg") ||(filetype == ".gif") ||(filetype == ".xls")||(filetype==".odt"))
{
var x = getSize(); if (x > 5242880)
{
alert('only upto 5 MB file is allowed');
return false;
}
}
else
{
alert('Only .doc, .pdf, .jpg, .gif, .xls is allowed');return false;
}
}
</script>
<form id="form1" runat="server">
<input type="file" name="b" id="file1" onchange="return checkFileType();" />
<div>
</div>
</form>
In the above code i am getting this line in code
" var oas = new ActiveXObject("Scripting.FileSystemObject");" getting Exception is "0x800a01ad - JavaScript runtime error: Automation server can't create object".
Can anyone tell me to how can i create ActiveX object properly and what i need setting and which DLL's i use and all can anyone help me out.
Thank You
This validation is not a supported method in all the browsers.
Anyway, for IE9 or below (where .files is not supported) you can use this. To use this method, you will need to enable activex object in IE.
Go to Internet Options->Security Tab. Select trusted website, and click Sites button. It will give you an option to add the url. Add the url of your site, and save. Then click on the button saying "custom levels". It will open a list of options. Find the one saying "Initialize and script activex controls not marked as safe" and enable it.
Save and close the dialog boxes, and refresh your webpage.
Edit:
Few notes:
This is extremely unsecure method, so I would suggest improving compatibility and saying no to anything below IE9.
Secondly, this is something you have to enable on every single user's machine. Otherwise, that line will always throw an exception.
So, if you have to stick to IE8 or lower, and have control over your userbase, then only use this. Otherwise, just use flash upload method for IE browsers. Your users might hate installing flash, but there is nothing you can do.
P.S. I was doing this same thing about an hour ago. Lucky for you, I did all the research. :)
Edit: On a secondary note, can someone help me figure out how to get rid of XML dataislands without major rewrite? That is the only thing stopping me from saying goodbye to IE6.
Related
I am trying to make a script for my Google spreadsheet in which I upload an XML file and process its data. I am able to create a form, display it in a modal dialog, but I get a strange error when I attempt to submit a form with a file: Nothing is logged for the error in Stackdriver Error Reporting. However, the web browser console logs the following error message:
Error: We're sorry, a server error occurred. Please wait a bit and try again.
The error message comes with a stack trace:
Zd https://n-z7hx4jjtvixobmaqkddve7tkcdyndjsnh3plmfq-0lu-script.googleusercontent.com/static/macros/client/js/2745927008-mae_html_user_bin_i18n_mae_html_user__en_gb.js:56
bf https://n-z7hx4jjtvixobmaqkddve7tkcdyndjsnh3plmfq-0lu-script.googleusercontent.com/static/macros/client/js/2745927008-mae_html_user_bin_i18n_mae_html_user__en_gb.js:71
G https://n-z7hx4jjtvixobmaqkddve7tkcdyndjsnh3plmfq-0lu-script.googleusercontent.com/static/macros/client/js/2745927008-mae_html_user_bin_i18n_mae_html_user__en_gb.js:15
J https://n-z7hx4jjtvixobmaqkddve7tkcdyndjsnh3plmfq-0lu-script.googleusercontent.com/static/macros/client/js/2745927008-mae_html_user_bin_i18n_mae_html_user__en_gb.js:99
Id https://n-z7hx4jjtvixobmaqkddve7tkcdyndjsnh3plmfq-0lu-script.googleusercontent.com/static/macros/client/js/2745927008-mae_html_user_bin_i18n_mae_html_user__en_gb.js:47
Ed https://n-z7hx4jjtvixobmaqkddve7tkcdyndjsnh3plmfq-0lu-script.googleusercontent.com/static/macros/client/js/2745927008-mae_html_user_bin_i18n_mae_html_user__en_gb.js:48
b https://n-z7hx4jjtvixobmaqkddve7tkcdyndjsnh3plmfq-0lu-script.googleusercontent.com/static/macros/client/js/2745927008-mae_html_user_bin_i18n_mae_html_user__en_gb.js:44
Of course, the stack trace doesn't help here, as it points to a huge minified JavaScript file on Google's servers.
I have tried replicating the examples in the current Google Apps documentation as well as a few old and recent examples I could find on StackOverflow, and the issue is always the same: When comes the time to submit the form data, the script crashes.
I know that this is specifically caused by the file input field. If I remove it, I'm able to submit the form and process its data. If I add the file input field, I get the error as soon as I submit the form.
I can tell the issue is not the file. I have tried uploading a big (125 kb) text file at first, followed by one a few bytes in size, and even not submitting any file at all, and I get the same error. I'm encountering this issue on both Chrome and Firefox, on two separate Google accounts.
Here is my Google script. The updateTracker method is called when clicking on a drawing object that I placed in the spreadhseet.
function updateTracker()
{
var thisUI = SpreadsheetApp.getUi();
var htmlUpdatePage = HtmlService.createHtmlOutputFromFile('myPage');
var updatePrompt = thisUI.showModalDialog(htmlUpdatePage, 'Update');
}
function digestXml(theForm) {
//var fileBlob = theForm.xmlFile;
var thisUI = SpreadsheetApp.getUi();
thisUI.alert("Test");
}
Here is my HTML file, "myPage":
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script>
// Prevent forms from submitting.
function preventFormSubmit() {
var forms = document.querySelectorAll('form');
for (var i = 0; i < forms.length; i++) {
forms[i].addEventListener('submit', function(event) {
event.preventDefault();
});
}
}
window.addEventListener('load', preventFormSubmit);
function submitXml(objForm)
{
google.script.run.withSuccessHandler(updateUrl).digestXml(objForm);
}
function updateUrl(url) {
var div = document.getElementById('output');
div.innerHTML = 'Got it!';
}
</script>
</head>
<body>
<form id="xmlForm" onsubmit="submitXml(this)">
<input type="file" value="Browse" name="xmlFile" />
<input type="submit" value="Digest" />
</form>
<div id="output"></div>
</body>
</html>
I can tell that the issue occurs precisely when trying to pass objForm from the HTML to the Google Script. I'm able to write to the console right before the line google.script.run.withSuccessHandler(updateUrl).digestXml(objForm); in HTML, but I don't get to thisUI.alert("Test"); in the Google Script. If I remove the parameter objForm from digestXml() in the HTML, the crash does not occur.
It appears that the issue only occurs in a recently released version of Google App's scripting interface, "V8".
When I create a script, I am prompted to use this version of their scripting interface. Trusting Google to test their functionalities, I accepted without thinking.
If I edit my script's configuration file to use STABLE instead of V8, I do not encounter the issue. If you're having this issue, here's how to do that:
Open the Script Editor.
In the top menu, select View > Show manifest file.
In the files list, open appsscript.json.
Replace "runtimeVersion": "V8" with "runtimeVersion": "STABLE"
Save.
This is however alarming as I presume the current stable version will be deprecated eventually in favor of V8. I logged an issue for this: https://issuetracker.google.com/issues/149980602
First of all, sorry for ressurrecting this question here.
I've been trying for two days how to reach this job using javascript/jquery and i think i've read all stack overflow and other blogs posts about that, so please, don't mark it as duplicated because I can't use out-dated scripts from 2012 now in 2017.
I've a single page that redirects to a third party e-learning platform where some content needs flash to work. Many users don't care about which software is installed on their machines (what a new, huh) so i need to detect it and show the tipical message "please install/update flash player clicking here", but i cannot find a "modern" script/way to do this, in any place, simplified, if possible.
All scripts i've tried are deprecated or returns false in all browsers, even i've newest version of flash installed and active.
Anny help will be appreciated (except links to older posts or scripts that don't work nowadays, obviously).
Thanks a lot!
There is a simple way to check for Flash since all the installed and enabled plugins will be listed in navigator.plugins;
Note that if a plugin is installed, but not enabled, it will not be detected in the navigator.plugins array. There is NO way to detect this using Javascript (this Question which confirms the same).
Having said that, use the following function isFlashEnabled(); to detect Flash :
<html>
<script>
if(isFlashEnabled())
{ document.write('Flash is installed (but may need to be enabled)'); }
else { document.write('Flash is either not installed or disabled'); }
function isFlashEnabled()
{
var flash = navigator.plugins.namedItem('Shockwave Flash');
if (!flash) { return 0; }
else { return 1; }
}
</script>
<body> <embed src="https://www.w3schools.com/tags/helloworld.swf"> </body>
</html>
You can get an array which contains all installed plugins of a browser like this:
var plugins = navigator.plugins;
Then you can then check if the array contains the flash plugin.
From https://developer.mozilla.org/de/docs/Web/API/NavigatorPlugins/plugins:
function getFlashVersion() {
var flash = navigator.plugins.namedItem('Shockwave Flash');
if (typeof flash != 'object') {
// flash is not present
return undefined;
}
if(flash.version){
return flash.version;
} else {
//No version property (e.g. in Chrome)
return flash.description.replace(/Shockwave Flash /,"");
}
}
This is a really strange one. Our company has has an InDesign script that, near the end, calls Acrobat (by way of Applescript) to open a PDF file, replace a page in it, then save the file and close it. We've been using this script for over a year and a half now with no issues on 8 of the 9 computers we have. That last one, however, is giving me an odd message when it tries to open and save the file.
To be clear, all 9 computers are Macs, all running OS X 10.9.5 Mavericks. The script is on a central server, so they're all using the same file:
var unlockCover2014 = app.trustedFunction(function (fName, fPrefix)
{
app.beginPriv();
var folderPrefix = fName.match(/^.*?(?=JOBS)/);
console.println("fName is " + fName);
console.println("folderPrefix is " + folderPrefix);
var myDoc = app.openDoc(folderPrefix + "Product Templates/ProofCoverNew/proof_cover_2014.pdf");
myDoc.replacePages(0, fName, 0, 0);
myDoc.saveAs(fName);
myDoc.closeDoc(true);
app.endPriv();
});
This file is stored in the correct folder to be a Folder-level script. 8 of the computers work through this without any trouble whatsoever. The 9th, however, puts this into Acrobat's Javascript console:
fName is /ArtDept/ArtDept/JOBS/425000-425999/425000 Folder/425000_cover.pdf
folderPrefix is /ArtDept/ArtDept/
RaiseError: This file is already open.
Doc.saveAs:9:
===> This file is already open.
I do not understand why this computer, alone, thinks that the PDF files are open already. The problem that arises from this is that, when the main InDesign script is done running, two documents are still open in Acrobat, and the one it's supposed to save does not get saved.
Any ideas about what's going on here?
I did finally discover what the problem was. I feel a bit silly about how (almost) obvious it is, but perhaps it might help others in my situation.
I disabled the line in the main InDesign script that was calling Acrobat, figuring I'd come back to that problem later after I dealt with some other issues. When I did so and ran the main script again, I discovered that Acrobat does, in fact, already open up a copy of that cover sheet PDF sometime during the execution of the main script! I was shocked, at first, but then I did a headdesk when I quickly realized the cause:
InDesign on this computer is set, by default, to automatically open a PDF after exporting it.
So, I just added a short line to the part of my code that sets the PDF Export Preferences to turn that feature off:
with (app.pdfExportPreferences)
{
pageRange = proofRange;
if (multiColor) pageRange = colorTable.toString();
useSecurity = true;
disallowChanging = true;
disallowCopying = false;
disallowDocumentAssembly = true;
disallowExtractionForAccessibility = false;
disallowFormFillIn = true;
disallowHiResPrinting = false;
disallowNotes = true;
disallowPlaintextMetadata = true;
disallowPrinting = false;
changeSecurityPassword = "(NOPE)";
viewPDF = false;
}
It's the viewPDF line at the end. (Sorry, I don't think I can highlight it with markdown.) I do feel silly that I overlooked such a semi-obvious cause, but I hope this might help someone else who is experiencing a similar issue. Thanks for trying to help anyway, #Loic.
Is it possible that the Acrobat script is ran while InDesign has not totally ended writing the PDF File if this is what we are talking about ? Or maybe there are some network latencies that make the file not reachable for the moment.
I would advice using a delay to (in)validate that theory.
delay 3
On another end, why do you need to replace file. I mean can't this be thought in InDesign Scripting Scope only ? Just curious.
I really need a way to copy some text to the OS clipboard in Firefox.
Know it is easy in IE and not possible in Chrome and Opera unless flash is used. Because of different reasons I am unable to use the flash solution!
Had it working in the past but now the netscape.security.PrivilegeManager.enablePrivilege is protected as far as I can figure out (since ver. 17).
It looks as if it is still possible according to this article:
https://developer.mozilla.org/en-US/docs/Using_the_Clipboard
Believe it is still necessary to enable the possibility in the user.js file like this
user_pref("capability.policy.policynames", "allowclipboard");
user_pref("capability.policy.allowclipboard.sites", "http://");
user_pref("capability.policy.allowclipboard.Clipboard.cutcopy", "allAccess");
But how shall I do it? Have made some test without great success and think there is no guide on the web that explain how it shall be done in a generic way. E.g. a simple guide about how to enable javascript access to the clipboard. Hopefully also a guide that can be used by the novice user. Like to do it and post it here but need a working solution first.
According to the web there are 2 solutions for copy to clipboard;
document.execCommand("copy", false, null)
and
var gClipboardHelper = Components.classes["#mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper);
gClipboardHelper.copyString("Put me on the clipboard, please.");
Both generate a failure with my first try.
The solution below need the user to press CTRL+C and I need a solution where the text shall copy based on the press of a button (many on a single page).
https://stackoverflow.com/questions/4344325/copy-to-clipboard-on-firefox-and-google-chrome/11346026#11346026
My old solution was like this:
var clip = Components.classes['#mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
if(clip)
{
var trans = Components.classes['#mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
if(trans)
{
var str = new Object();
var len = new Object();
var str = Components.classes["#mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
if(str)
{
var clipid=Components.interfaces.nsIClipboard;
if(clipid)
{
str.data = cliptext;
trans.addDataFlavor('text/unicode');
trans.setTransferData("text/unicode", str, cliptext.length*2);
clip.setData(trans, null, clipid.kGlobalClipboard); // No return value
return 0;
}
}
}
}
Components.classes is undefined in unprivileged code (not add-on etc) so I do not believe any solution with this will work any more. One option is to make an add-on that will execute in privileged code area and send the text that shall be copied to this add-on for it to handle the copy to the OS clipboard (nice new possible project).
This only leave document.execCommand("copy", false, null) in the field as a stand alone solution.
Tried this code and it does not copy anything to the OS clipboard - but do not generate any errors btw.
var pre = document.getElementById('pcryptcopytext');
if(!pre)
{
pre = document.createElement("pre");
pre.setAttribute('id', 'pcryptcopytext');
pre.setAttribute('style', 'opacity: 0; position: absolute; top: -10000px; right: 0;');
document.body.appendChild(pre);
}
pre.innerHTML = cliptext;
pre.contentEditable = true;
//pre.unselectable = "off";
//pre.focus();
if (document.createRange)
{
var rng = document.createRange();
rng.selectNodeContents(pre);
document.execCommand("copy", false, null);
document.body.removeChild(pre);
}
So, anybody got a working solution?
Looks like this is not supported any more, and there is no replacement :(
https://support.mozilla.org/en-US/questions/977068#answer-500083
Maybe making some noise in a Firefox bug will help us get a (safe) solution.
Solved by creating a Firefox Add-on that exposes the clipboard object: https://github.com/myplaceonline/myplaceonline_ffclipboard
Example:
if (window.ffclipboard) {
window.ffclipboard.setText("clipboard text");
}
You can use firefox navigator object
navigator.clipboard.writeText("text you want to copy").then(() => {
// on success
}, (e) => {
// on error
});
document.execCommand("copy");
I have the great job of having to finish off a job originally given to a contractor but was never completed. Not a problem however I've now been told that the system must support Firefox 3.6! Not great but not something I would lose sleep over until now! The system has a Ajax function that uses the FormData object and then uploads a document (usually a PDF). I've ran this through Firefox 3.6 and I get the following
"FormData is not defined"
var formData = new FormData($('form')[0]);
That's fine as I can see that this object isn't supported, I just need to use a different method or means of collection... I used this:
var formData = Components.classes["#mozilla.org/files/formdata;1"]
.createInstance(Components.interfaces.nsIDOMFormData);
However this gave me the following error!
Permission denied for http://10.29.100.23:8080 to get property
XPCComponents.classes
I was unsure why this was... is the path "#mozilla.org/files/formdata;1" incorrect? I did more research and was getting nowhere! So I then thought about serializing the form changed the following to...
var formData = {};
$.each($('form')[0].serializeArray(), function(_, kv) {
if (formData.hasOwnProperty(kv.name)) {
formData[kv.name] = $.makeArray(formData[kv.name]);
formData[kv.name].push(kv.value);
}else {
formData[kv.name] = kv.value;
}
});
although this didn#t error the Ajax function wasn't uploading (I presume it wasn't recognizing or finding the file or it was just collecting a string for the file value). Does anyone have any recommendations on an alternative for FormData in older browsers, especially Firefox 3.6 - that's the only old browser I have to support.
** update ****
this is the content of the form on the HTML page
<form action="" method="post" enctype="multipart/form-data" name="uploadForm" id="uploadForm" target="#">
<label for="fileField">Rechnung hochladen</label>
<input type="file" name="fileField" id="fileField">
<progress id="progressbar" class="progressbar_margin hidden"></progress>
</form>
FormData is an XMLHttpRequest Level 2 interface that makes it easy to submit a form (including file uploads) using XHR / Ajax. As you've discovered, it's only available in Firefox from version 4 onwards. (The MDN documentation has a browser compatibility table.)
I suggest trying the jQuery Form Plugin. It supports an iframe fallback for uploading files in older browsers.
I think you should use this before your code:
netscape.security.PrivilegeManager.enablePrivilege(
'UniversalXPConnect'
);
To be sure also do this:
type "about:config" in your address bar;
search for "signed.applets.codebase_principal_support" ;
Set the value to true;
Hope it works , good luck.