Tryied window.open with Ajax, window.print not working (IE9) - javascript

I'm trying to open new window and send form data with javascript and jquery-1.8.3.
With Bernhard's help I succeeded to call a new window with page for print.
(Thank you so much Bernhard. window.open and sending form data not working)
But, window.print() function does not working in IE9! (FF, Chorme do well)
I refreshed the page, then IE9 calls window.print()
Here is source code.
Print this
<script type="text/javascript" src="/common/js/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
function printPage(){
$.post('/common/print.jsp', {view:$("#ctn").html()}).success(function(response){
var oWindow = window.open('', "printWindow", "width=700px,height=800px");
oWindow.document.write(response);
oWindow.print(); // I added this line. But IE9 not working.
});
}
</script>
Is there something I missed?

Try this one:
$.post('/common/print.jsp', {view:$("#ctn").html()}).success(function(response){
var oWindow = window.open('', "printWindow", "width=700px,height=800px");
oWindow.document.write(response);
oWindow.document.close();
oWindow.focus();
oWindow.print(); // I added this line. But IE9 not working.
});
checkout this:
Using HTTP Headers to Force Standards View in Internet Explorer 8 and Above
You can also use meta tags to force standards mode. The X-UA-Compatible meta tag tells Internet Explorer what view mode to use or emulate.
By setting this meta tag, you tell IE to use standards mode even if there are comments or an XML declaration above the DOCTYPE. You determine what version of Internet Explorer can best view the page, and then set the meta tags to define that version.
IE 7:
<meta http-equiv="X-UA-Compatible" value="IE=7">
IE 8:
<meta http-equiv="X-UA-Compatible" value="IE=8">
IE 9:
<meta http-equiv="X-UA-Compatible" value="IE=9">
If a customer comes to a page with a view mode higher than it supports
(e.g. an IE 7 browser viewing a page asking for IE8 view mode), it
will ignore the tag and render the page the the mode it would have
without the tag.
More info find here: http://webdesign.about.com/od/internetexplorer/qt/force-compatibility-view-in-ie.htm

Related

IE11 JQuery error?

I have code that works fine in Firefox and Chrome but not in IE 11. I'm getting next error messages:
1) SCRIPT5009: '$' is undefined
For this line of code:
$.extend({
)}
2)SCRIPT5009: 'jQuery' is undefined
// Browser globals
factory( jQuery );
3)SCRIPT1010: Expected identifier
.catch( function( error ) {
jQuery.readyException( error );
} );
Here is my header tag with all includes:
<head>
<script type="text/javascript" src="jquery/jquery-3.1.1.js"></script>
<script type="text/javascript" src="jquery/jquery-ui.js"></script>
<script type="text/javascript" src="jquery/JQuery_alert.js"></script>
<link rel="stylesheet" type="text/css" href="jquery/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="jquery/jquery-ui.structure.css">
<link rel="stylesheet" type="text/css" href="jquery/jquery-ui.theme.css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
I found that if I open my dev tools in IE and then in the upper right corner click on the Document mode and switch to Edge my code with all the includes above works fine. So my question is what is Edge? How I can make sure that someone else using IE will not have the problems running my page? Is there the way to fix that? Thanks in advance.
Compatibility View
When Internet Explorer runs in compatibility view, it emulates older versions such as IE8 which is incompatible with the latest version of jQuery (only the 1.x versions of jQuery are compatible with older versions of IE).
Checking if Compatibility View is the Problem
When you hit F12 in Internet Explorer, it should bring up the Developer Tools. Near the top right of the toolbar, you should find a drop down that lets you switch between Edge, 10, 9, 8, 7, and 5. Switching it will cause the page to refresh using the new document mode. If you switch to Edge and you still get the jQuery errors, then you can rule out compatibility view as the problem.
Making sure the page won't be displayed in Compatibility View
Check the documentation here regarding specifying document modes for Internet Explorer: https://msdn.microsoft.com/en-US/library/jj676915.aspx
You can also try to force IE11 to display in Edge mode by inserting a <meta> tag into the Header of your HTML (it should be the first tag within the Header) like so:
<html>
<head>
<meta http-equiv="x-ua-compatible" content="IE=edge">
...
This instructs Internet Explorer to explicitly use that document mode.
You can also experience issues if your jquery references are stored in a .jspf file that is referenced as an include. IBM Websphere will cache the jspf's in a temp folder on the server and they will not be replaced even with a ear/war deploy. It is necessary to remove those files from the temp folder.

window.close not closing window in HTA application

In my HTA application I'm using a JavaScript calendar window, it opens using window.open() and closed using window.close(), when the user clicks on one of the dates. This calendar works fine on multiple browsers and versions over more than 10 years. It even works in HTA applications most of the time.
However on specific workstations running IE11. The window.close() command is simply ignored, resulting in the window left open. On other IE11 workstations it works fine. I figured that turning off the "Enable Protected Mode" checkbox on IE11, Internet Options, Security tab resolves the problem on one of the problematic workstation. However, other workstations works fine with this setting turned on and turning off this setting is not an acceptable solution.
Code sample which reproduces the problem:
HTA application
<HTML>
<HEAD>
<HTA:APPLICATION ID="OpenCloseExample" BORDER="thick" BORDERSTYLE="complex"/>
<TITLE>Open Close HTA container</TITLE>
</HEAD>
<iframe width="1024px" height="768px" src="http://localhost:28080/openclose.html"/>
</HTML>
openclose.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Main Page</title>
<script src="openclose.js"></script>
</head>
<body>
open
</body>
</html>
openclose.js
var win;
function openWindow() {
win = window.open("", "_blank", 'width=250,height=250,status=no,resizable=no,location=no,top=100,left=100');
win.document.writeln("<html><head><script src='openclose.js'></script></head><a href='#' onclick='javascript:window.opener.closeWindow()'>close</a></html>");
}
function closeWindow() {
win.window.close();
}
I can't see this working in any IE with any settings. The problem is this string: <script src='openclose.js'></script>. That is, a literal ending script tag in a string works as an ending script tag on a page, when HTML parser will find it. This means, that your script was never loaded.
To fix this, you've to break the literal tag, for example like so:
<script src='openclose.js'><\/script>
Since you have pointed out that IE11 is causing the JS not to work, you can force IE to render in an older version very easily.
<meta http-equiv="X-UA-Compatible" content="IE=9">
This meta tag is very popular amongst HTA applications for utilizing JS/ActiveX methods/properties within specific IE versions (most of them being deprecated).
For more information, visit the X-UA-Compatible Tag Wiki
Hope this helps
I figured this out eventually.
Changing:
open
to:
open
Has resolved the problem

IE8 site keeps going into Quirk mode with JS added into the page

We have a site that's running perfectly in all browsers except IE8.
What happens is that it falls into Quirks mode forcefully by the browser due to the reason unknown to me.
And yes, it breaks the site really bad.
What's more weird is that it adds somekind of JS on its own to the code (when checked through View Source.
This is what it's showing:-
<SCRIPT language="JavaScript">
<!--
document.cookie = "IV_JCT=%2Fapchannel-lop; path=/";
//-->
</SCRIPT>
<!DOCTYPE html>
<html lang="en">
<head profile="http://www.w3.org/1999/xhtml/vocab">
<meta http-equiv="x-ua-compatible" content="IE=Edge"/>
...
The <SCRIPT> in the start is not added by me and is being added by IE8.
I have tried the following
First line <!DOCTYPE html> and then right after <head>, I wrote <meta http-equiv="x-ua-compatible" content="IE=Edge"/>
Adding respond
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
Nothing works.
Any idea how I can stop this and just force it to load with IE8 standard mode?
Thanks
The problem is that you're adding the script before the <!DOCTYPE>.
The doctype must be the very first thing on the page, otherwise IE will go into quirks mode. (even blank lines at the top of the page have been known to affect this)
Move your script somewhere else in the page, ideally inside the <head> element, and ensure that you have valid HTML markup, and the problem will resolve itself.
IE 8 will not mangle HTML like that. Something else must be responsible.
From AJAX techniques within a Tivoli Access Manager WebSEAL Environment:
Junction cookies
Issue
When you create a WebSEAL junction using the -j option to enable
junction cookies, special HTML code is inserted at the beginning or
end of the HTTP response that sets the correct cookie path in the
browser (the location determined by the -j option). Generally, the
returned page will look similar to that in Listing 11.
Listing 11. Example of junction cookie insertion
<SCRIPT>
document.cookie = "IV_JCT=%2Fjunction_name";
</SCRIPT>
<html>
<title>Example page </title>
<body>
Rest of the document...
.
.
.
That's a pretty specific bit of JavaScript (Debugging tip: When weird variable names show up in your code and you don't know where they came from: Type them into Google), so its a reasonable bet that this is what is responsible.
It doesn't sound like there is a work around, so your options seem to come down to:
Stop using IE 8. It is unsupported by Microsoft and no supported operating system that can run it can't be upgraded to a newer version of IE (they could also be upgraded to a non-IE browser).
Stop using WebSEAL (or at least WebSEAL junctions using the -j option) since it invalidates your HTML.

page opens in IE7 document mode instead of IE9

I know many variations of this question have been asked here but so far no solutions I have tried work for me.
I would like my web app to open in IE9 document mode in IE. When I open the page now, it always opens in 'Internet Explorer7 Standards), while 'Internet Explorer9 standards' is listed as the page default.
I have tried several variations of tagss, including
<meta http-equiv="X-UA-Compatible" value="IE=Edge">
and
<meta http-equiv="X-UA-Compatible" content="IE=7,IE=9">
(both right after the head tag)
I have also tried conditional statements, such as this example from S.O.:
<!--[if IE 7 ]> <body class="ie7> <![endif]-->
<!--[if IE 8 ]> <body class="ie8> <![endif]-->
<!--[if gt IE 8]><!--><body><!--<![endif]-->
Currently I am using: <!DOCTYPE html>
Of course I can manually switch the mode in F12, but I would like to site to open directly in IE9 Document mode (the Compatibility mode always defaults to IE9 Compatibility mode).
Currently I am working on an intranet development server; I have read that this may be a factor? But I would really prefer any solutions to be client-side, that I can add to the JS/HTML.....
Developer Tools Manually Overriding the Document Mode
If Internet Explorer 9 Standards is listed as the Page Default, this means you may have manually changed it to Internet Explorer 7 Standards via the tools. Just switch it back to Internet Explorer 9 Standards in the F12 Developer Tools themselves.
The tools will remember your explicit request to show the page in another Document Mode, and as such not revert to the page default. Consider the following from MSDN:
When you first load a webpage, F12 tools determines the default Document Mode and selects the appropriate mode. The text Page default in parentheses indicates the default mode of the webpage. A check mark appears next to the current mode of the document. Changing the mode causes the webpage to refresh, and remains in this mode until another mode is chosen or the browser is closed.
— Navigating the F12 Developer Tools Interface (emphasis in original)
If you'd like confirm this answer, open up a new browser window and navigate to http://stackoverflow.com. You should note in the F12 Developer Tools that it loads with a Document Mode of "Standards" (IE9 Standards if you're in IE9).
Switch Stack Overflow's Document Mode to IE7 Standards and refresh the browser. After refreshing you'll find that the browser stays with Document Mode: Internet Explorer 7 Standards, and lists Internet Explorer 9 Standards as (Page Default).
Compatibility View Settings
According to the MSDN resource How Internet Explorer Chooses Between Document Modes, the only other potential cause for this would be Compatibility View Settings.
In Internet Explorer 9, click Tools, then Compatibility View Settings. You can find your settings for Intranet sites there. In Internet Explorer 10 (Desktop Mode), you may have to press Alt to reveal the Tools menu item.
Just put following code and your IE browser would open by default in defined compatible view.
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9">
You can change "IE=EmulateIE9" to "IE=EmulateIE8" if you want make IE8 as default compatibility view.
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8">
The issue in my case was that a group policy had been applied on my company-issued laptop which explicitly set the domain that I was using to render in Compatibility Mode. I found this by checking the IE console (F12):
And I verified this by running the following command on my machine, which generated a report of applied group policies on my machine:
gpresult /h C:\gpresult.html
The report had a section like this, which included the root domain of the website I was working on:
You can put the following code sample too.
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
This will load your application in the default browser mode. And specially make sure to include this meta tag as the first tag just after the head tag. Other wise it will not work.

Force only part of a page into IE7 compatibility mode

I know you can force a whole page in IE8 or IE9 to render in IE7 mode by adding the meta tag
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">
But how can I make it so only part of the page gets rendered in this compatibility mode? I don't want to use iframes.
Unfortunately, you can't. But if you have access to the page, why can't you make it entirely compatible with all versions of IE?

Categories

Resources