Open Word document from Internet Explorer on intranet - javascript

We have an internal website for document management. When you choose to open a document, it run the following script to open the file:
012-010-01
<SCRIPT language=javascript>
function opendokument(dokument){
var objAppl;
try{
objAppl = GetObject("","Word.Application");
objAppl.Documents.open(dokument);
}
catch(exception){
objAppl = new ActiveXObject("Word.Application");
objAppl.Visible = true;
objAppl.Documents.open(dokument);
}
objAppl = null;
}
</script>
The problem is that the macros in the document is not running correctly now as we move from Windows XP with Office 2003 to Windows 7 with Office 2007 (See my previous post)
If I run the script locally on my computer or if I open the documents manually macros work properly. How do I get this to work? Any setting I can do in Word or Internet Explorer, or can I rewrite the script on the site that open documents.

Try allowing all kind of scripts in IE. I believe there was something about macroses...

I guess the issues is reated to Security setting of IE.

Related

Identify an opend Webbrowser with ShellExecute properly to work with document.getElement

I need to automation my job by filing Forms in webpage by js,I made a code like this:
var ie = new ActiveXObject("InternetExplorer.Application");
ie.visible = true;
ie.navigate("http://www.google.com");
while (ie.busy) WScript.Sleep(100);
ie.document.getElementsByName('q')[0].value ="3";
var Butn = ie.document.getElementsByName('btnK')[0];
Butn.click();
but I want this code work with another web browser (e.g.Firefox) so I tried something like this:
var ie = new ActiveXObject("Shell.Application");
var commandtoRun ="C:\\Program Files\\Mozilla Firefox\\firefox.exe";
ie.ShellExecute(commandtoRun,"http://www.google.com", "1");
while (ie.busy) WScript.Sleep(100);
ie.document.getElementsByName('q')[0].value ="3";
var Butn = ie.document.getElementsByName('btnK')[0];
Butn.click();
but this code throw an error:
'ie.document' is null or not an object
800A13F
I ask for any of these tow ways:
*dealing with a web browser already opened not only open one then applying the code.
*Identify the opened web browser in proper way to apply the code.
I can see that you are using an ActiveX object that is only supported by the IE browser.
This object is a Microsoft extension and is supported in Internet Explorer only.
If you are looking to automate the other browsers like Firefox, I suggest try to check Selenium web driver. I think that it is more suitable product to fulfill your requirements.
It is available to automate the browsers using many developing languages.
It looks like it is also possible to get an object of already opened browser.
See here: Can we use Selenium to work with an already open browser session?

Get username from ActiveXObject("WScript.Network") not working?

I need a way to get a User's name from a web application that will be used in FireFox, Chrome, and IE. I have a javascript function in my code that is the onclick function for a button. The button is supposed to show an alert with the user's name. For some reason this is not working in my code. I am debugging in Visual Studio 2015, and I have opened VS as an administrator. I am attempting to run this code in Firefox and IE and nothing shows up. Is there another way to do this? Am I doing this wrong?
My HTML Code
<button onclick="getUser()">GET USER</button>
<script>
function getUser() {
var net = new ActiveXObject("WScript.Network");
alert(net.username);
}
</script>
ActiveX is a technology that was only ever supported in Internet Explorer and which isn't supported in the most recent versions of that browser.
There is no standard way to get information about the system username of the browser user from a webpage.

Any way to detect URI schema is available in windows using JavaScript in IE

I found few ways to detect where window support current URI scheme for Firefox and Chrome browser, if application not registered i will download and register those application uri
Chrome
var appWindow = window.open('alert:"Hello%20World"',"_self");
if(appWindow!=null){alert("it is worked")}
Firefox
$("body").append('<span id="__protoProxy"></span>');
function queryWord(aWord)
{
var protoProxy = document.getElementById('__protoProxy');
if (protoProxy)
{
var word = aWord.replace('"','\"');
protoProxy.innerHTML = '<div style="display:none;"><iframe id="iframe01" src="alert://'+ word + '"></iframe></div>';
}
}
queryWord('hello world');
if(document.getElementById('iframe01').contentDocument.body.innerHTML!=""){alert("it is worked")}
IE
but in IE i am unable to perform this action even though URI is not registered in windows, IE open window to select app from windows store.
Is there any way to detect in IE ?
Is there any way to detect it commonly across all browser ?
How does citrix launcher works in all browser?
This question appears to be a duplicate, however since there is a bounty I receive an error that it cannot be closed.
In any case, check out this thread and see if it works for you.
Link.

Google Chrome Won't Accept .contentDocument or .contentWindow

When I try my code out:
Testing.html -
<script language="JavaScript" type="text/javascript">
function find() {
var iframeEl = document.getElementById('love');
if ( iframeEl.contentDocument ) {
var form = iframeEl.contentDocument.document.getElementById('hi').getAttribute('href');
alert(form)
} else if ( iframeEl.contentWindow ) {
var form = iframeEl.contentWindow.document.getElementById('hi').getAttribute('href');
alert(form)
}
}
</script>
<body onload="find()">
<iframe name="lovez" src="frame.html" id="love">Testingz</iframe>
</body>
Frame.html -
Testing
It will not return an alert box. However on Internet Explorer it will. I have been searching the internet, trying all examples and can't find a simple example that will work in Google Chrome. Am I doing something wrong or is it just Google Chrome?
I've noticed that both the contentDocument and getSVGDocument (for svg objects from svg files) will work fine if the code is from a web server, but when I copy the code to a local file, it will not work.
Here's a sample link with a code I coppied from which works on the web but not from my disk.
Here's the solution I just found from Chrome (thanks to Artem S), i.e. using the --allow-file-access-from-files flag.
Try it without the .document
var form = iframeEl.contentDocument.getElementById('hi').getAttribute('href');
instead of
var form = iframeEl.contentDocument.document.getElementById('hi').getAttribute('href');
The answer from #IsraelGav is correct in the sense that this problem occurs when the code is accessed from a local file but not when accessed from a web server. It is also correct in the sense that using the --allow-file-access-from-files flag can allow the local file to be accessed by Chrome.
However, it misses an important security concern here. Both the concern, as well as an alternative possible solution, were originally described in this other SO answer by #orszaczky. To summarize the alternative solution: On Windows, install http-server (npm install -g http-server) and run http-server from your project directory. On Mac/Linux, run python -m SimpleHttpServer from your local directory. You can now access the locally hosted web site in your browser. On Windows I had to use localhost:8080 while on the Mac I had to use localhost:8000.
By the way, this is not only an issue for Chrome (v49.0) but also for Opera (v35.0), on both Windows and Mac.

Accessing and modifying tabs opened using window.open in Google Chrome

I used to be able to do this to create an exported HTML page containing some data. But the code is not working with the latest version of Google Chrome (It works all right with Chrome 5.0.307.11 beta and all other major browsers).
function createExport(text) {
var target = window.open();
target.title = 'Memonaut - Exported View';
target.document.open();
target.document.write(text);
target.document.close();
}
Chrome now complains that the domains don't match and disallows the JavaScript calls as unsafe. How can I access and modify the document of a newly opened browser-tab in such a scenario?
I also got this problem when using a local page using the file:// protocol (in Chromium 5.0.342.9 (Developer Build 43360) under Linux). The exact error message is:
Unsafe JavaScript attempt to access
frame with URL about:blank from frame
with URL
file:///home/foo/bar/index.htm.
Domains, protocols and ports must
match.
Apparently the protocols don't match, but the good news is: when this page on a web server, Chromium also opens a new window as "about:blank", but it doesn't complain any longer. It also works when using a local web server accessed via http://localhost.
EDIT: there is bug filed upstream about this. According to this comment, it is fixed and it will be rolled into trunk shortly.
UPDATE: this bug is now fixed, the following test case works properly:
var target = window.open();
target.title = 'Memonaut - Exported View';
target.document.open();
target.document.write("test");
target.document.close();
Here is the explanation I think
http://groups.google.com/group/chromium-dev/browse_thread/thread/9844b1823037d297?pli=1
Are you accessing any data from other domain? Not sure, but that might be causing this problem.
One alternative would be a data: protocol URL.
https://developer.mozilla.org/en/data_URIs
http://msdn.microsoft.com/en-us/library/cc848897%28VS.85%29.aspx
var durl = "data:text/html," + encodeURIComponent(text);
var target = window.open(durl);
Supported in all modern browsers except IE7 and below.
you can also try closing self tab/window by using this code,
originally I've made this small greasemonkey script sometime ago in order to close
bad popups and ad windows, it worked fair (not too brilliant though)...
//window.addEventListener("load", function () {
window.addEventListener("onbeforeunload", function () {
try {
// clear inner html content to prevent malicious JS overrides.
document.getElementsByTagName("html")[0].innerHTML = "";
window.open("javascript:window.close();", "_self", "");
window.open("javascript:window.close();", "_self", "");
}
catch (e) {}
}(), false);

Categories

Resources