[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

IE - Window.Focus - Strange Problem

Posted on 2006-06-28
11
Medium Priority
?
299 Views
Last Modified: 2008-02-01
Hello All

I'm having very strange problems with window focus in internet explorer.

1.  I've my default.aspx and in that I'm opening a new asp page called  Edi.aspx using
      Dim jscriptStr As String
                jscriptStr = "<script language=JavaScript> window.open('Edi.aspx','editorWin','height=5,width=555,left=300,top=300,toolbar=0,location=0, directories=0,status=0,menubar=0,scrollbars=no,resizable=0,titlebar=no');</script>"
                RegisterClientScriptBlock("clientScript", jscriptStr)

 In the Edi.aspx body tag I'm putting onload="javascript:top.focus();".

This is not working and the Edi.aspx is hiding behind the default.aspx. why is this happening? At the same time when I used this technique for a opening different page other.aspx its working.

Another big thing is- the above technique is working perfectly fine in firefox browser for both Edi.aspx and other.aspx.

I'm using IE.6.0.


2. Is there any way to access the controls in Edi.aspx from the default.aspx ( here Edi.aspx is opened from the default.aspx using window.open('Edi.aspx'))?


Thanks for your help
Aditya


0
Comment
Question by:adityaiiii
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
11 Comments
 
LVL 29

Expert Comment

by:Pravin Asar
ID: 17004645
If you have assign the window variable, you could get the document object (and its children).


var nw = window.open('Edi.aspx','editorWin','height=5,width=555,left=300,top=300,toolbar=0,location=0, directories=0,status=0,menubar=0,scrollbars=no,resizable=0,titlebar=no');

alert ('Access Document Object ' + nw.document);

0
 

Author Comment

by:adityaiiii
ID: 17004853
Hello pravina

Do you know anything about the problem 1.? also can you please expand the above answer more ?

Thanks
Aditya
0
 
LVL 29

Expert Comment

by:Pravin Asar
ID: 17004927
1. If window has been opened by window.open , it's parent window
   can be accessed by

   window.opener

to focus on the parent window, you can use window.opener.focus() ;

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:adityaiiii
ID: 17004962
I know that pravina.  Here Its the other way around. I want to access the controls in the new window from parent window. Is there any method for that ?
0
 
LVL 29

Accepted Solution

by:
Pravin Asar earned 2000 total points
ID: 17005080
Here is a comprehensive example for you.


<html>
<head>
<title>Open/Close Windows</title>
</head>

<body>
<script language="javascript">
if (window.opener) {
     alert ('Parent ' + window.opener);
      if (window.opener.opener) {
           alert ('GrandParent ' + window.opener.opener);
      }
}
var nw = null;
function OpenNewWin (loc) {
nw = window.open (loc,'');
self.focus();
}
function GetChildsTag (tagId) {
if (!nw) { return; }
alert (nw.document.getElementById(tagId).innerHTML);
}
</script>
<p>
This is a demo page for
<br>1. Click on "Open Window.
<br>This opens same document on new window.
<br>
<br>2. Click on "Open Window" in newly window.
<br>This opens same document on another window.
<br> This window has parent and grandparent.
<br> Click on "Close Window". This will close the this parent and reassigns the
<br> parent as GrandParent.
</p>
<form name="form1">
<input type="button" value="Open Window" onClick="OpenNewWin(window.location.href); ">
<input type="button" value="Close Parent Window" onClick="temp = window.opener.opener; window.opener.close(); window.opener = temp;">
<input type="button" value="Get time from child window" onclick="GetChildsTag('div1');">
</form>
<div id="div1">
</div>
<script language="javascript">
document.getElementById('div1').innerHTML = (new Date()).toString();
</script>
</body>
</html>
0
 

Author Comment

by:adityaiiii
ID: 17005835
Hello

I need to access  child from  parent. I know how to access a parent window from child window. Please tell me how to access Web controls in child window from parent window where child window is opened from parent window using window.open.
0
 

Author Comment

by:adityaiiii
ID: 17006255
One more thing, the webcontrols in the child page are ASP controls
0
 

Expert Comment

by:narnikhil
ID: 17007777
You can try doing this:
<script>
var newWin = window.open("index.aspx");
          if(newWin!=null)
          {
               //this will get you the background color of the new window in the old window
              alert(newWin.document.bgColor);
          }
</script>

Warning: If you try to open a page in a different domain than the one on which your site is hosted, then you will get an exception in Javascript.
0
 
LVL 29

Expert Comment

by:Pravin Asar
ID: 17008381
>>I need to access  child from  parent.
I know how to access a parent window from child window. Please tell me how to access Web controls in child window >>from parent window where child window is opened from parent window using window.open.

Did you read my post completely ???
 

Did you look at the code

function GetChildsTag (tagId) {
if (!nw) { return; }
alert (nw.document.getElementById(tagId).innerHTML);
}

That gets the elements from child window .

I said earlier that I am posting a comprehensive example how to get the parent window and child window.



Good Luck to You.


_PA
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question