window.opener.document.getElementById(..) does not work in IE - javascript

Im trying to open new window from parent window when user choose to print the parent window ,i re-draw the parent page in the new page by using :
document.getElementById('demo_tab_info').innerHTML=window.opener.document.getElementById('demo_tab_info').innerHTML;
and then i control the element by javascript(hide some and show some of them).
That work fine with Firefox and Chrome ,but it is not with IE,does there an explanation for this?
also
window.print();
Does not work with Chrome? Can any one help with these two problems?

As for second question.
Function:
window.print()
is supported in all major browser (source: http://www.w3schools.com/jsref/met_win_print.asp)
But it is true that it is not standardized function by W3C (https://developer.mozilla.org/en/DOM:window.print).

Related

window.open() parameters not working in Edge

In Servicenow, I have a requirement to open a new window from a UI action.
1. Open in New window (not tab)
2. Display the navigation toolbar (buttons)
3. Display scrollbars
4. Be resizeable
Using var window = window.open(url, windowName, [windowFeatures]); appears to work fine in Chrome and Firefox, but in IE the window parameters are largely ignored. height and width seem to be the only ones that are adhered to.
I am using Microsoft Edge 41.16299.248.0 and I cannot get a new window opened with the toolbar showing no matter what I try.
https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_win_open5
This is the test code:
myFunction() { window.open("https://www.google.com/search?q=help", "_blank", "toolbar=yes,width=600,height=400,left=600,top=500,status=yes,scrollbars=no,resize=no");
}
When I click the button, a new window opens, no toolbar, not positioned according to left/top, no status bar, I DO see scroll bars, and I CAN resize.
Here is an example from MSDN:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms644696%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
According to MS, they've adopted " MDN Web Docs as the definitive place for useful, unbiased, browser-agnostic documentation for current and emerging standards-based web technologies. ", but I do not find any explanation of this issue I am experiencing.
https://learn.microsoft.com/en-us/microsoft-edge/dev-guide
Is this a known issue with IE Edge or is there some sort of workaround available?
ServiceNow has made public that some features will no longer be supported on Microsoft Edge. Why don't you try with another browser like Mozilla or Chrome? It never fails those two to me.
Opera might have some issues too, so I don't advise using that one.
Here's the link about the supported browsers:
https://docs.servicenow.com/bundle/paris-release-notes/page/administer/navigation-and-ui/reference/browser-support.html
Hope this information helped :D
Cheers!
Try using Glide Navigation API:
g_navigation.openPopup('incident_list.do?sysparm_query=active=true', 'Active Incidents', 'resizable,scrollbars,status', true);
try this
function win_open1() {
window.open('about:blank','','titlebar=yes,toolbar=yes,location=yes,status=no,menubar=yes,scrollbars=yes,resizable=yes,width=700,Height=300,left=0,top=0');
}
We encountered the same issues. It turned out that if the "location=" parameter is included, Edge completely ignores all the parameters.
Removing that parameter allowed the others to work.
window.open (url, null,"height=200,width=200,status=yes,toolbar=yes,menubar=yes,location=yes,resizable=yes");
Fails - window opens with same size as parent window.
window.open (url, null,"height=200,width=200,status=yes,toolbar=yes,menubar=yes,resizable=yes");
Works fine - window opens 200x200 pixels.

how return focus on parent window using javascript?

is it possible return focus on tab parent using javascript?
I read some threads about this problem, but i didn't find solutions.
I tried
window.opener.parent.focus()
and
window.opener.focus();
but it doesn't work.
Can someone help me?
Thanks
Generally, you cannot do this inside a web page. Because it's the user's choice which tab/window she wants to focus on and browsers such as firefox and chrome respect such choices by providing configs to open new tabs in the background or not. But under several very special cases, you may still achieve this.
If you want to open a new tab and return focus immediately, you can try to simulate a 'ctrl+click' event on a link to open the tab on the background. Refer to this thread Open a new tab in the background?(Only for chrome, API may already changed. So it may only works on an obsoleted version)
If you are shipping with an extension, do it in the extension code. For example: in chrome extension.
If your script is for a customized browsers which you have control on / you can affect the design, you can implement the function in the browser side and expose an API for your script.

Is there any way to bring a popup front with javascript?

I am writing a web application and I open some popup windows with respect to user events.
Now I want to avoid from having too many opened popups, so I decided to bring already opened popup front instead of pop a new one.
In my researches I saw that there was a method called window.focus in old browsers like before Chrome 20 or so, but this method is no longer available because of over usage for advertisement.
Is there any solid way or even workaround to bring an already opened up popup front in javascript?
Thanks,
Ugurcan
I came up with a workaround for Chrome. In javascript, when you use window.alert method, Chrome brings according window to the front, but this is not applicible for Firefox and IE.
I will use this workaround for now. Only problem here is that, one does not simply decorate window.alert pop-up box.
We can just use css z-index to bring it at front and z-index is supported in effectively all browsers (since IE6+, Firefox 2+, Chrome 1+ etc) as per caniuse.com

IE9 Window Loses Focus due to jQuery Mobile

In our product, we're using the most recent development version of jQuery Mobile in our ASP.NET website. Each and every time we do an ASP.NET postback, the browser window goes to the back of the screen.
Example:
Maximize any window. Example: Visual
Studio, Word, Windows Explorer.
Maximize IE9 over it. IE9 is the only
thing you see on the screen.
Click on a button in our solution that does
a postback.
IE9 is no longer visible.
Whatever was behind it now has focus
(and fills the screen, as it is
maximized)
Only workarounds I know:
Don't include the jQuery mobile scripts.
Ensure IE9 is the only maximized window in Windows.
I don't know what jQuery Mobile is doing in the background and am assuming this is a bug in IE9 that will eventually be fixed. However, if you had any tips on how to prevent it from happening in the meantime, that would be great.
Edit: Seems it isn't on every postback. It is on every postback that performs a Response.Redirect. I should add that all my postback are actually utilizing ASP.NET AJAX, not full postbacks.
I know this is an old post, but for people coming here from Google:
I ran into this same issue today. It seems this lose focus behavior is what IE does when you trigger the blur event on the window object. This was the code that caused this issue for me:
$(document.activeElement).blur();
activeElement will default to the body element when there are no other elements in focus, and the blur event then bubbles up to the window. To fix this I simply did a check like:
if (document.activeElement != $('body')[0]) {
$(document.activeElement).blur();
}
I had similar problem with IE10 and jQuery 1.7.2.
I found these lines in my code:
$(document.activeElement).blur();
and
$(':focus').blur();
So, adding simple .not('body') resolves the problem:
$(document.activeElement).not('body').blur();
$(':focus').not('body').blur();
This same issue seems to occur with jQuery Mobile 1.4.2.
When using IE 10, with a single tab open and another window on the same monitor, if you open a popup it will send the browser to the background.
To fix this you have to edit the _handleDocumentFocusIn function. You need to change the line(10391) that reads:
target.blur();
to
if (targetElement.nodeName.toLowerCase() !== "body")
{
target.blur();
}
I made a pull request so hopefully this will be included in the next version.
Just posting this link to anybody who is experiencing more of this continued mess. I am seeing the problem on IE 9 and IE 10 on a window.location = 'BLAH', from within the Angular location resource.
This doesn't seem to solve the problem for me, but it may help others:
http://support.microsoft.com/kb/2600156/en-us

window.showModalDialog vs. window.open

What are situation when you want to use window.showModalDialog function? It seams that you can do exactly the same with window.open function and few parameters that remove some of the chrome (navigation, addressbar, etc...)
When would you want to use window.showModalDialog and window.open?
It has been a few years since this question was originally asked and things have changed a bit since then. window.showModalDialog is now officially standardized as part of HTML5 and is supported in IE, Firefox 3+, Chrome (albeit buggy), and Safari 5.1+.
Unfortunately window.showModalDialog is still plagued by a number of issues.
Modal dialogs are blocked as popups by default in Firefox, Chrome, and Safari.
The modal dialogs in Chrome are buggy and aren't truly modal - see http://code.google.com/p/chromium/issues/detail?id=16045 & http://code.google.com/p/chromium/issues/detail?id=42939.
All browsers except Chrome block the user from interacting with the entire window (favorites, browser controls, other tabs, etc...) when a modal dialog is up.
They're a pain to debug because they halt JavaScript execution in the parent window while waiting for the modal dialog to complete.
No mobile browsers support window.showModalDialog.
Therefore it's still not a good idea to use window.showModalDialog. If you need the window opened to be modal (i.e. the user cannot interact with the rest of the page until they deal with the dialog) I would suggest using jQuery UI's dialog plugin.
window.open will work for non modal windows but I would stick with jQuery UI's dialog because opening new windows tends to annoy users.
If you're interested I write about this in more detail on my blog - http://tjvantoll.com/2012/05/02/showmodaldialog-what-it-is-and-why-you-should-never-use-it/.
Modal dialogs are dialogs that once opened by the parent, do not allow you to focus on the parent until the dialog is closed.
One could use a modal dialog for a login form, edit form, etc where you want to have a popup for user interaction but not allow the user to return to the window that opened the popup.
As a side note, I believe only Internet Explorer implementes window.showModalDialog, so that kind of limits your usage of it.
showModalDialog() is currently being standardized as part of HTML5. The third argument (for additional options) is not present in the HTML5 version, and is (safely) ignored by Safari and Chrome.
http://dev.w3.org/html5/spec//user-prompts.html#dialogs-implemented-using-separate-documents
Note that there's a bug in Chrome 2 which prevents showModalDialog() from loading properly. The popup window appears, but the content never loads.
One more reason to avoid using showModalDialog().
showModalDialog()works well in Internet Explorer, Firefox (3 and above)
Works in Chrome but popup is not model (you can go to parent window)
Note that while you can show modal from any popup window, you cannot use window.open from a model dialog in some browsers (IE, Safari).

Categories

Resources