473,237 Members | 1,265 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,237 software developers and data experts.

IE javascript window.open problem

Hello,

I am using the following javascript code to open a new window.
Somehow, IE always opens a new window. It doesn't open target url in
the window name given.

All i want is, if there is a window "MyWin" already open, then the
main window should load the target url in "MyWin" and not open a new
window again.

<!-- Code Starts -->
<html><head></head>
<Script Language="javascript">
function Callme()
{
var win2 = window.open("Test2.htm", "MyWin");
}

/* I don't want to use following type of code as it serves the purpose
initially but not if you refresh the main page.*/
/*
function Callme(location){
var win2;
if (typeof win2 == "object") {
win2.location.replace(location);
}
else{
win2=window.open(location,"MyWin",null,true);
}
}
// thanks
*/

</Script>
<body>
<form>
<input type="button" value="Click Me" onClick="Callme();">
</form>
</body>
</html>
<!-- Code Ends -->

Any hint/help apprreciated.
IE version : 6.0.2800.1106.xpsp2.030422-1633
OS : Windows XP

Thanks,
Samir
Jul 23 '05 #1
2 3466
Samir Pandey wrote:
Hello,

I am using the following javascript code to open a new window.
Somehow, IE always opens a new window. It doesn't open target url in
the window name given.

All i want is, if there is a window "MyWin" already open, then the
main window should load the target url in "MyWin" and not open a new
window again.

<!-- Code Starts -->
<html><head></head>
<Script Language="javascript">
<script> tags should appear either inside <head>...</head> or inside
<body>...</body>.

The "language" attribute is deprecated. Use type="text/javascript"
instead.
function Callme()
{
var win2 = window.open("Test2.htm", "MyWin");
}

/* I don't want to use following type of code as it serves the purpose
initially but not if you refresh the main page.*/
/*
function Callme(location){
var win2;
if (typeof win2 == "object") {


Because you are declaring win2 on every call to the function, it will
_never_ be typeof "object". If you want to do something like this, use a
global variable to track the existance of win2. This task is covered in
the FAQ:

<url: http://jibbering.com/faq/#FAQ4_10 />

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 23 '05 #2
Samir Pandey wrote:
I am using the following javascript code to open a new window.
Somehow, IE always opens a new window. It doesn't open target url in
the window name given.

All i want is, if there is a window "MyWin" already open, then the
main window should load the target url in "MyWin" and not open a new
window again.

<!-- Code Starts -->
<html><head></head>
In Valid (X)HTML, the "head" element must not be empty. It must at
least contain a "title" element. Besides, have you used a proper
DOCTYPE declaration? If not, that would make the document invalid,
too. You cannot build a house on a swamp.
<Script Language="javascript">
<script type="text/javascript">
function Callme()
{
var win2 = window.open("Test2.htm", "MyWin");
}

/* I don't want to use following type of code as it serves the purpose
initially but not if you refresh the main page.*/
/*
function Callme(location){
var win2;
if (typeof win2 == "object") {
Since win2 is declared local (note the `var' keyword), this branch will
be never executed as `win2''s value and type is always `undefined'.
win2.location.replace(location);
}
else{
win2=window.open(location,"MyWin",null,true);
You maybe run into a scope problem here. `location' is already a
property of the window object. Use another variable identifier.

window.open has only three arguments: The URI of the resource to
access, the internal name of the new Window object, and a *string*
containing definitions of its features. I wonder what you think
`null' and `true' will do.

And there is no need to check if the window is already open if you use
a unique internal window name. If it is not open, it will be opened,
if it is still open, it will be reused. All you may want to do is to
focus the window so it does not remain in the background if it is reused.
}
}
function isMethodType(s)
{
return (s == "function" || s == "object");
}

function callMe(sURI)
{
var result = window.open(sURI, "MyWin", "");

if (result && isMethodType(typeof result.focus))
{
result.focus();
}

return result;
}

var win2;
// ...
win2 = callMe("a_fool");
// thanks
?
*/
As you comment everything out, ...
</Script>
</script>
<body>
<form>
<input type="button" value="Click Me" onClick="Callme();">
.... why do you expect this to work anyway?
[...]
IE version : 6.0.2800.1106.xpsp2.030422-1633
OS : Windows XP


Ohh, would just anyone post this precise information in the first place!
PointedEars
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Kai Grossjohann | last post by:
It seems that Ctrl-N in Mozilla opens a new empty browser window. That's fine, I don't need to do anything about it. But Ctrl-N in IE appears to clone the current window. Is there a way to...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.