473,320 Members | 1,848 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,320 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 3474
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: 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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.