Strange behaviour opening pop-up window in Internet Explorer - javascript

I have the following JavaScript code to pop up a window in Internet Explorer. The code is executed from a page within a Microsoft CRM modal dialog box. (RequestID is a string that is always the same in the test system - at the moment it contains "abcdefg" - without the quotes).
var cancelUrl = "CancelRequest.aspx?RequestID=" + RequestID;
alert("About to open a window.\n\n" + cancelUrl);
window.open(cancelUrl);
alert("Window opened");
I expect to see a message telling me that I am about to open a window. I then expect to see a window open and get another message about the window having been opened. I don't really care about the order of the last two events; the alerts are there so I know the code has been executed.
I have two PCs and a virtual PC. All running IE7. On the Windows 2003 VPC, the messages and pop-up appear every time without fail.
On the Vista PC and WinXP PC, the messages appear but the pop-up only appears intermittently. (I think this may be the case on the Vista PC too).
All three have identical settings in IE. All have the IE pop-up blocker disabled and have no other pop-up blockers installed.
Can anyone shed any light on this?

Ah, I think I got it... missed it in the description...
You are trying to open a non-modal window from a modal dialog in IE.
This AFAIK, should not work.
Try opening another modal window instead.
Effectively you are saying...
on window A, open up modal window B, now open up non-modal window C, which isn't really valid.

This code is simple. Use debugger and see what is going on.
Check that site with FireFox or Chrome, they have JS debuggers.
Edit:
Add try/catch block around window.open() and see if there is some exception there.
Edit 2:
I see now that you are sending characters as RequestId. You should check if that URL can handle that kind of value. Since name is RequestId I'd say that there is big chance that there should be numeric only parameter. If that is correct, then it can happen that server side crashes when you try to open window and then nothing happens. Reason more to set try/catch block and test.

You might want to try Firebug lite, which will work for IE.
http://getfirebug.com/lite.html
The try/catch other people have mentioned is also a good idea. I think.
Additionally, is there any chance that the pop-up is trying to use a window that is already open but minimized. So it doesn't appear to be working but it's really just reloading the minimized window?

Related

Can't open chrome inspector with javascript prompt is running

I'm trying to open the Chrome inspector to see the console log and I can't.
It works very well with Firefox but not with Chrome.
The chrome development tools is enabled and works well when there is no prompt or alert pop up running.
I have a little program in which I have a prompt that asks the user to give a number.
Explanations for the user are in the console(console.log("xxxx")), so when the page is loaded and the prompt is on the screen, the user would have to open the inspector window to see what choice he/she should make.
Here is my code:
console.log("1\n2");
var saisie = prompt("What is your choice");
alert(saisie);
I would like the user to see the console log before they answer the prompt.
You can use window.console to access and interact via javascript with the debug console. Then you can pipe its contents to a div on the page.
alert is blocking, which is why people tell you not to use it (or leave snarky comments to that effect). 'Blocking' means that nothing else can happen: it literally hijacks the entire tab. Meaning that you can't, say, open chrome devtools without dismissing the alert first. I have no idea how this is actually working in FF.
Pro-tip: don't ever use alert. Ever. Use a modal dialog, iframe, whatever. Don't use alert.

How to close current browse's tab?

I am trying to close the current open tab after 1 second.
Here is what I tried :
$(function(e){
setTimeout("window.top.close()", 1000)
)};
The code works in Edge but it does not work in Firefox.
I get this warning into the console when I try to close a page in Firefox :
Scripts may not close windows that were not opened by script.
How can I close the page?
Simply you can not. The fact Microsoft Edge allows you to close tabs is a serious security breach, other safer internet browsers will not let you do something like that.
You can close tabs and windows which were opened by the script itself.
Your code seems correct anyway.

Open the Chrome Inspector via code to catch quick breakpoints?

Here is the situation. A popup window contains the javascript I need to debug. It also contains a re-direct that happens so fast I can't open the Inspector fast enough to have the breakpoints fire. I start with the Inspector open and click a link which closes the Inspector and opens the popup window which contains the javascript. But the logic happens and the re-direct fires so fast I can't open the Inspector before Chrome is already off the popup with the script I need to debug.
I've read the Google documentation and setting breakpoints works great but the breakpoints only fire if the Inspector is open.
I tried using debugger; which I found from this SA answer but once again, it only fires if the Inspector is open.
Just to debug it, I also tried setting a "sleep" function (which chews up processor, is bad etc) like this:
function sleep(milliSeconds){
var startTime = new Date().getTime(); // get the current time
while (new Date().getTime() < startTime + milliSeconds); // hog cpu
}
sleep(5000);
That didn't work either.
Is there a way to get the Inspector to pop open via code? If not, what is the best way to debug this?
Thanks.
I've been struggling with this issue all day and finally hit upon a solution. Simply place an alert in your code before the debugger statenent:
alert('Time to attach the debugger');
debugger;
When the alert appears on the screen, simply click the "inspect" link in Chrome Inspector. The inspector will attach to your page and you can then click OK on the alert box to continue. It will then stop at the debugger statement

Chrome & PopUp window names

I am opening pop up windows from a website (flash content) the following way:
RING = window.open(path,'RING_Projekt','width=800,height=600,scrollbars=no,top=' + t + ',left=' + l +'');
The HTML file opened in the popup is valid HTML with a <title>, yet Chrome (all other browsers do work fine) will display "Untitled" in the title bar.
Does anyone know why this is happening and if there is an error / workaround that could fix this? Or is this some kind of a pop up blocker malfunction / bug?
Thanks!
EDIT: Playing around, I noticed the following (unfortunately it ADDS to my confusion...): the page with the flash content opens another popup (displaying news) on load by doing:
var NEWS = window.open('popup/news.htm','RING_news','width=400,height=400,scrollbars=no,top=20, left=20');
When I now open a popup with the function mentioned in the above post, then go and close the news-Popup opened on load and then switch back to the "on-click"-Popup the popup magically acquired a name. When you close this and open it again, the name is gone again.
To be honest: I don't get it. I should be able to have more than one pop-up, right? Also, I cannot see any naming problems or anything else that could explain this behavior.
Am I missing something big here? Or is this a plain bug?
Ok, I am a 99.99% sure this is a Chrome bug, so I'll answer this myself.
Chrome seems to read the specified title correctly from the HTML (as it will be displayed in the task bar), but seems to have problems when having to display the name in the bar on the popup (see screenshot below). When you start to fiddle with the popup (move / resize), the title will sometimes appear and disappear again. Yet, the names in the task bar will always be right (that plus the fact that it works in every other browser lets me think it is a bug).
I am running Chrome 14.0.835.186 m on Windows Vista.
http://code.google.com/p/chromium/issues/detail?id=113201
its a open bug
This is a bug with Chrome. However, there is a workaround for this.
If you put the following script in the page that opens in the popup window, it seems to work fine.
<script language"text/javascript">this.window.resizeBy(1,1);this.window.resizeBy(-1,-1);</script>
The second argument to window.open isn't the <title> of the new window, used by <a target="...">, for example.. The title is determined by the content of the page.
See MDN docs for more info.

Strange Window popup behaviour on IE7

We have written a small javascript function which checks if a URL should open in same window or a popup. In cases when a url should open in a new window IE is giving some strange behaviour a window popup flashes and closes with a beep sound. Can anybody suggest whats going behind the scenes i do not think its my javascript which is wrong. Is it some browser weird behaviour.
I suspect you have a third party pop-up blocker installed.
Yep, this sounds like some third party stuff. By default IE will try to guess what it should do with popups (open in a popup window, open in a new tab, don't open at all) but it won't try to open a window and close it immediately (unless caused by some addons or code included in the page). JavaScript errors shouldn't cause the window to close either (unless they really call window.close()).

Categories

Resources