Window.Close() following a Mailto Javascript call not working in IE9 - javascript

I have a JSP page that pops in a new window from an application I am working on, retrieves email information, along with other data and constructs some email meta data. The code then triggers a basic mailto: call which pops up local mail client. The page that calls the mail client is supposed to close via a basic window.close but it remains open after the mail client is launched. The same code works in Firefox/Chrome. Ive stripped out all the JSP code but the below is the basis of the page, and the same issue occurs with this lightweight version.
<html>
<head>
</head>
<div class='PagePanel'>
<a id="SendEmail" href="mailto:test#test.com"></a>
<script language="JavaScript">
document.getElementById('SendEmail').click();
</script>
<script language="JavaScript">
// automatically close the newly launched browser window displaying this page as no widgets are painted on this page
window.close();
</script>
</div>
</html>
Any one know why the page doesn't close in IE9? (IE9 support needed) Closes in Firefox and Chrome.

Related

window.close() dose'nt work script may close only the windows that were opened by it

I have an application which, after sending a form, directly closes the window page.
I have to login and after login, I am redirected to an another page where I fill out a form, and after sending the form the window page is closed automaticly.
I use this script
<script type="text/javascript">
window.open('','_parent','');
window.close();
</script>
but it not closes the page that is open after the login page.
Thank you
As per my understanding you want to open a new page and then later close it. When you are opening a new page, you also need to keep its reference in the current scope in order to have control over it. Try the below code:
<script type="text/javascript">
var newPage = window.open('','_parent','');
newPage.close();
</script>

Open an external url from a web page without the warning

I am trying to open an external url "https://stackoverflow.com/" on a new tab on opening a page in internet explorer. I have the code for it but when I try to open the page it gives me this dialog box screenshot below. Once I click on Allow Blocked Content then it opens my page in a new tab :
I do not want the user to make any changes to his Internet explorer settings. Is there any changes I can make my code open the "https://stackoverflow.com/" url without the above dialog box ?
<html>
<head>
<script>
function LoadF() {
window.open('https://stackoverflow.com/')
}
</script>
</head>
<body>
<body onload = "LoadF()">
<center><a target="_blank" href="https://stackoverflow.com/">Stack Overflow</a></center>
</body>
</html>
As a shameless copy-paster, It is my duty to notify you that this question was already answered.
To summarize, there are two major points to note:
This bar will only appear when running the page locally, and should not therefore appear when loading the page from a web server.
You can add a line at the top of your code to tell IE that the local file is safe: <!-- saved from url=(0014)about:internet -->

Dismiss an Alert shown by another application

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"

javascript: launch new window, redirect existing one, set focus in new window - how to?

I'm having a problem trying to get this to work. Here's my situation:
- using SAP Portal I'm launching an html page with the code below
- the html page needs to launch a brand new window
- the existing html page then needs to redirect itself back to the main portal page
- the newly launched window then needs to be brought to the forefront (set focus)
The issue is that when the portal reloads after being redirected it takes focus. I also don't have access to the code of the application that I've launched in the new window so can't do anything there.
Here is the code I'm trying to use. I've also tried to use a setTimeout() as well but it doesn't work.
<html lang="en-US">
<head>
<meta charset="UTF-8">
<script type="text/javascript">
window.open('https://passwordresetprogram','_blank');
window.top.location.href="http://originalurl";
</script>
<title>Password Reset</title>
</head>
<body>
</body>
</html>
when I tried the commands in console
window.open('https://passwordresetprogram','_blank');
window.top.location.href="http://originalurl";
it works as you mentioned
the html page needs to launch a brand new window
the existing html page then needs to redirect itself back to the main portal page
the newly launched window then needs to be brought to the forefront (set focus)
and
to access the code of the application launched in new window, try this
<script type="text/javascript">
var popUp="";
function OpenNew(passedURL){
popUp = window.open('https://passwordresetprogram','_blank');
popUp.document.getElementById("<some_selecior>").<some_attribute>=<some_code>;
}
</script>

java script not working in chrome

I am working on a website in which I want to close the browser window/tab when the Logout Successful page loads. I am doing this because after the Logout workflow if 'back' button is pressed on browser, it displays the previous page with all the confidential info visible. Since I cleared the session in the corresponding servlet, user cannot do anything after the logout but display of data is of quite concern.
For this pupose I am using below code (Logout.jsp)-
<body onload="self.close();">
<center>
You have been successfully logged out.<br>
</center>
</body>
The problem is that the above code is working fine on IE however, it is not working on Firefox and Chrome. I checked all the settings related to Java Script for Chrome and they are exactly the same as of my browser.
Alternatively, I tried to clear the history. For this purpose I used below code which I found on some website -
<body onload="window.history.forward(0)">
<center>
You have been successfully logged out.<br>
Kindly close the browser for security reasons.<br>
</center>
</body>
But this code is not working in any of the browser.
Any kind of help would be appreciated.
---------------- UPDATE ---------------
For the second option (i.e. clearing history), after much google and work, I was able to make it work. The solution is as below -
If a user follows the navigation page1 -> page2. And you want to stop user from page2 to go back to page1 then add below code on page1 -
<body onload="window.history.forward();">
//rest of the body
</body>
I tested it in IE and found it working perfectly.
Now, I am left with the original issue that why script is not working in Chrome.
Do not do that. Just verify if the session exists. If it doesn't ( since it logged off ) you send him automatically to login page. That way your site is hack proof because i can eliminate from firebug or any console the line where you just close my tab, and therefor i can still see the data.

Categories