Dismiss an Alert shown by another application - javascript

I have a question that may seem slightly vague, but I am not sure how to go about solving it.
Our office runs a headless machine that is a print server, connect via third party software. The issue that I am having, is that if for whatever reason, the system becomes disconnected from the host server, by means of connection issues on either our end, or theirs, an Alert dialog appears, and the printing will be halted until the dialog is dismissed.
The application is run through Internet Explorer, and appears with with the following dialog.
I originally tries using Java, and a Robot to blindly click the okay button, however the issue is that the dialog will appear in different places each time, and sometimes the message will appear multiple times if not dismissed immediately, so blindly clicking a screen coordinate will not work.
My next thought was to search for a PID, and kill each message by name, or PID, however because it is an Internet Explorer application, that is not a possibility.
Any thoughts as to how I could blindly dismiss these messages, either automatically, or through an external signal?
Edit
I have determined that the dialog is created using JavaScript, and I now have an alteration to the question, how can I dismiss this alert() call? I have read that using JavaScript, you can not dismiss the message, but would there be a way to inject a custom script, to overrride the call to alert?
i.e., a dead function that overrides the system alert?
function alert(){
// do nothing
}
How could I append this to the already loaded page...?

I suppose you don't have access to the source code of the print server app so the best way for you to do is add a bookmarklet which contains a javascript code overriding the alert.
A bookmarklet basically is a piece of code stored as a bookmark in a web browser
To create a bookmarklet, open up Notepad and create an HTML page with this content:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<a id="codeOut" href="javascript:(function(){ window.alert = function(){};})();">Your Bookmarklet</a>
</body>
</html>
Save the file as "Bookmarklet.html"
Open the file with Internet Explorer
Right-click on the "Your Bookmarklet" hyperlink, select "Add to favorites" and give it a name
Once your application is loaded and your bookmarklet added, in IE select Favorites->"Name of your bookmarklet"

Related

Bizarre IE bug with excel plugin

This bug in our legacy app is blowing my mind. I don't even know how to describe it to google to search for good help. This is all in Internet Explorer as this older app doesn't support anything else.
I click on the menu (which is in a different frame of a frameset from the main content frame) to load the page.
On the page is a link to download an excel spreadsheet in a separate window with excel (MIME type is application/vnd.ms-excel).
While the link does work, excel issues TWO requests to our servlet without passing the JSESSIONID, which is odd, but the requests don't seem to matter if we just bail out of the request and return nonsense. The file was already downloaded.
BUT WAIT, it gets weirder. If you hit the link TWICE without closing excel, and then try to click anything in the menu frame, the javascript runs, the servlet responds (I can see the right HTML returned in the network tab), but the main content window DOES NOT CHANGE. Clicking something in the main content window DOES work (there's a popup window button).
There are no javascript errors in the console. If I close excel the tab remains unresponsive, but the problem does not affect OTHER browser tabs. Note that it's so dead that clicking the refresh button on the browser does nothing. And yet...the debugger shows js does run, and the main window popup does respond.
I'm mostly confident that this is something to do with the excel. Is there a known bug or something?

Server webpage window - open + print + close

In a web-based ERP , we need to print POS reciept on the client . When I click print on client another web page opens up, and I have to click print again so that it goes into the printer. Then I have to close the window and then go back to data entry webpage page again.
How can I print from the client browser most efficiently? i.e. After the data is saved, I click print and it opens, prints and closes the browser window automatically. How can this be achieved? In offline versions it happens, but when i take it on browser it doesn't occur. Pls help
Front end:- .NET, HTML5, Javascript, Jquery
Backend (Database):- MS SQL
There is one way to print a page using JavaScript, excluding additional libraries. It uses a method called window.print()
You seemed to suggest that you wanted to remove the prompt that happens with the window.print() method. I don't recommend this behaviour, as most people don't want their printer suddenly spitting out paper, not to mention that this is technically malware. However, assuming you have a legitimate use case for this behaviour, there is a duplicate question with answers already.
HTML / Javascript One Click Print (no dialogs)

Javascript redirecting on everypage can't remove

I have a javascript file that was accidentally added to the admin side of our site. The javascript is below,
<script>
if (document.getElementById("errorTitle") != null && document.getElementById("errorTitle").innerHTML === "Insufficient Privileges") {
window.location.replace("/portal/InsufficientPrivileges");
} else {
window.location.replace("/portal/FileNotFound");
}
</script>
The problem is that this code runs on the admin pages so we are unable to remove it. If we disable javascript on the browser the page never renders, dynamic content. How can we disable this from running so we can upload the proper file?
You might be able to edit the page that contains the reference to the problem file. If you can just edit the page to jump over where that code is called with an if statement or goto.
If you can't edit the other pages then you can Use the debugger to change the code executed on the fly. Chrome and Firefox have debuggers that should be able to do this.
Specifically for Chrome you go into the object inspector (available via menus or right clicking on the page). Then you can see the HTML on the left window. You select the script tag of interest, you can right click and select delete or select "Edit HTML"
If the page redirects you before you're even able to edit anything, you can use automated tools.
Fiddler (Windows)
Fiddler lets you see all pages downloaded, and then you can have it send your browser a different page when it tries downloading any page you specify (AutoResponder feature). This way you can temporarily edit a page while you can fix it in the admin panel.
Greasemonkey (Firefox) or Tampermonkey (Chrome)
These plugins let you run JavaScript code on a page as soon as it gets to your browser. This will let you do things such as removing the script tag programmatically.

How to download a file from a modal Dialog that posts back to itself?

ASP.Net Webforms pages are wrapped in a massive form, which restricts other forms on the page because nested forms don't work. This is intentional because in a webforms project, there can only be one form per page, and all of the server/client interaction require it. In order to build a custom form, I put together a modal dialog in this way. In order to allow for proper error messages from the server, my modal dialog has to post back to itself. In order to do this, I followed this trick to use the form target as the name of the window the dialog is in.
The problem comes when I try to add a button to download a file. When I try to download a file from this dialog now, nothing happens. I can redirect my response to the file in question, but I can't write the file to the response because the dialog box just sits there when I click the button and nothing happens.
After quite some time researching and building a small test case, I found out that there are several interesting factors here.
Response.WriteFile() works fine in webforms, even when the form is set with a target of the current window.
Modal dialogs can download files perfectly fine, unless the form is set to the target of the current window.
Through extensive testing, this appears to be an obscure bug, or perhaps even a strange attempt at security. This also appears to be specific to IE 8, though I didn't get to test other versions of IE.
The trick to allowing the download inside the modal dialog is to change the form's target.
function downloader() {
document.getElementById("form1").target = "_blank";
}
This fixes the IE bug and appears to work in all other browsers (though I couldn't get opera to show the pop up at all, even with "allow all popups").
Thought my day of toiling shouldn't go to waste and maybe this will help someone else in the future.

Printing a Word document from IE without opening print dialog

I have a requirement where I need to print a specific word document when I click on a button in IE8/IE9. I tried to find a way using ExecWB and other methods but could not achieve my goal. Couple of constraints I have are as follows.
The word document is availble through URL and this URL is from a different site than the page where I am clicking the button to print (XSS considerations ?)
I need to directly print using default printer without popping up the print dialog.
Is this possible in anyway?
Impossible from within the context of HTML page, without a custom browser extension. Word document must open before it's printed (maybe not visually presented to the user upon opening, but MS Word or some other application that is capable of opening word docs must be installed on the client system. There is Office extension for IE, which can be used to open the document, but the user has to click on the print button to invoke the dialog. There's nothing that you can do from within javascript to accomplish that. I'm sure you could, if you wrote your own IE extension/plugin, but unless your users are corporate that must install it, nobody else will.
I hope I'm not lying to you.

Categories