By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,425 Members | 2,549 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,425 IT Pros & Developers. It's quick & easy.

Trouble opening a window using tabs navigation

P: 7
Hello i have a button that clicking on it should open a pop-up with a calendar.

I'm working with IE 7.

the behaviour that follows clicking on the button is not persistent.

if i use the mouse to click the button i succeed, but when i navigate with tabs, sometimes it works right away, sometimes it needs 1-2 tries to open the window, and sometimes it doesn't succeed.

the problem is that
Expand|Select|Wrap|Line Numbers
  1. window.open(...)
returns null

This is my code-

Expand|Select|Wrap|Line Numbers
  1. function cal_popup1 (str_datetime) {
  2.     this.dt_current = this.prs_tsmp(str_datetime ? str_datetime : this.target.value);
  3.     if (!this.dt_current) return;
  4.  
  5.     var obj_calwindow = null;
  6.     var counter = 0;
  7.     while (obj_calwindow == null && counter < 10)
  8.     {
  9.         var obj_calwindow = window.open(
  10.         this.path + 'calendar.html?datetime=' + this.dt_current.valueOf()+ '&id=' + this.id,
  11.         'Calendar', 'width=200,height='+(this.time_comp ? 215 : 190)+
  12.         ',status=no,resizable=no,top=200,left=200,dependent=yes,alwaysRaised=yes'
  13.         );
  14.         alert("hello " + obj_calwindow);
  15.         counter++;
  16.     }
  17.  
  18.     if (obj_calwindow == null)
  19.     {
  20.         alert("couldn't open the window");
  21.     } else {
  22.         obj_calwindow.opener = window;
  23.         obj_calwindow.focus();
  24.     }
  25. }
i would appreciate your help
Jan 15 '08 #1
Share this Question
Share on Google+
13 Replies


acoder
Expert Mod 15k+
P: 16,027
Welcome to TSDN!

So how do you call this code? Can you show the button HTML markup.
Jan 15 '08 #2

P: 7
this is how i call the script

Expand|Select|Wrap|Line Numbers
  1. <tr>
  2.     <td width="17">&nbsp;</td>
  3.     <td class="text1" align="left" valign="middle" height="30">From date:</td>
  4.     <td align="left" valign="bottom" height="30">
  5.         <input type="Text" id="ONLINE_FROM"
  6.                 name="ONLINE_FROM"
  7.                 class="textbox" size=20 
  8.                 style="WIDTH: 152px"
  9.                 value="15/01/2008"/>
  10.         <span id='calStRef'>
  11.             <a href='javascript:calStart.popup();'>
  12.                 <img src="/images/cal.gif"  style='position:relative; top: 3px' border="0" alt="calendar"/>
  13.             </a>
  14.       </span>
  15.     </td>
  16. </tr>
and this is how calStart is
Expand|Select|Wrap|Line Numbers
  1. var calStart = new calendar1(document.forms['mmitab'].elements['ONLINE_FROM']);
and in calendar1

the code contains a reference to the first method that i wrote
Expand|Select|Wrap|Line Numbers
  1. function calendar1(obj_target) {
  2. ...
  3.     this.popup    = cal_popup1;
  4. ...
  5. }
one more thing i discovered - if i put the marker using the mouse on one field before the calendar button and i use 'tab' or 'shift+tab' than the pop-up opens OK

?
Jan 15 '08 #3

acoder
Expert Mod 15k+
P: 16,027
if i use the mouse to click the button i succeed, but when i navigate with tabs, sometimes it works right away, sometimes it needs 1-2 tries to open the window, and sometimes it doesn't succeed.
I don't seem to experience this problem. Can you give a test link which demonstrates the problem? Does this only occur in IE7 or in other browsers too?
Jan 16 '08 #4

P: 7
I don't seem to experience this problem. Can you give a test link which demonstrates the problem? Does this only occur in IE7 or in other browsers too?
thanks for your help, i can't give a test link since it's part of a bigger system.

i tested it on IE6 and FF as well.

in IE6 this behaviour is reproduced and in FF it works fine.

i thought that maybe something is lost or reset during the tabs navigation...

i also thought that it might be related to some pop-up blocking - but i turned it off and it didn't work.

do you know what could make the
Expand|Select|Wrap|Line Numbers
  1. window.open(...)
fail?
Jan 16 '08 #5

acoder
Expert Mod 15k+
P: 16,027
I assume by tabs navigation you mean pressing the tab key and then when the link receives focus pressing the return key?
Jan 16 '08 #6

P: 7
I assume by tabs navigation you mean pressing the tab key and then when the link receives focus pressing the return key?
Yes, this is what i mean
Jan 16 '08 #7

acoder
Expert Mod 15k+
P: 16,027
The only thing I can think of right now is that IE sometimes has a problem with th "javascript:" protocol in the href attribute (it's bad practice anyway - the href should always point to a real URL). So, the line:
[HTML]<a href='javascript:calStart.popup();'>[/HTML] could be changed to:[HTML]<a href='somepage.html' onclick="calStart.popup(); return false;">[/HTML] See if that makes a difference.
Jan 16 '08 #8

P: 7
The only thing I can think of right now is that IE sometimes has a problem with th "javascript:" protocol in the href attribute (it's bad practice anyway - the href should always point to a real URL). So, the line:
[HTML]<a href='javascript:calStart.popup();'>[/HTML] could be changed to:[HTML]<a href='somepage.html' onclick="calStart.popup(); return false;">[/HTML] See if that makes a difference.
Hello,

i tried your suggestion but it didn't help entirely,
i figured that if i don't you the mouse at all before i press return on the button it doesn't work.

only after i place the marker using the mouse on some field and navigate from there, your solution works better, although not 100% of the time.

the keyboard navigation is supposed to be transparent, No?

i have another button on the screen that after i reach it using the tabs I'm not able to continue to other control using 'tab' or 'shift'+'tab'

any idea?
Jan 17 '08 #9

acoder
Expert Mod 15k+
P: 16,027
i tried your suggestion but it didn't help entirely,
i figured that if i don't you the mouse at all before i press return on the button it doesn't work.

only after i place the marker using the mouse on some field and navigate from there, your solution works better, although not 100% of the time.

the keyboard navigation is supposed to be transparent, No?
I see what you mean. The window has to have focus for the keyboard tab navigation to work. What originally has focus?
i have another button on the screen that after i reach it using the tabs I'm not able to continue to other control using 'tab' or 'shift'+'tab'

any idea?
Post the code for this button. Is it the last button?
Jan 18 '08 #10

P: 7
I see what you mean. The window has to have focus for the keyboard tab navigation to work. What originally has focus??
what initially gets the focus is the last control added to the page, when i start to move with the tabs. i start from that button

[HTML]<TD align="left"><INPUT type="button" name="cancelButton" class="BtnCreate" value="<i18n:message key="link.cancel"/>" onclick="window.close()" style="width : 80;"></TD>[/HTML]

Post the code for this button. Is it the last button?
i found the problem the button had an attribute [HTML]onFocus="window.focus()"[/HTML], after i removed it the tabs go O.K.

so now the only problem is that the window doesn't open :(
Jan 20 '08 #11

acoder
Expert Mod 15k+
P: 16,027
i found the problem the button had an attribute [HTML]onFocus="window.focus()"[/HTML], after i removed it the tabs go O.K.
Well, that was going to cause problems. Good spot.
so now the only problem is that the window doesn't open :(
Even if the button/link has focus?
Jan 21 '08 #12

P: 7
Even if the button/link has focus?
what do you mean has focus?
when i hit return it attempts to open the pop-up - this means that it has focus, right?
Jan 21 '08 #13

acoder
Expert Mod 15k+
P: 16,027
what do you mean has focus?
when i hit return it attempts to open the pop-up - this means that it has focus, right?
Yes, that's correct. Can you produce a test version that demonstrates this problem?
Jan 21 '08 #14

Post your reply

Sign in to post your reply or Sign up for a free account.