Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

what's wrong with this simple, one line code?

Status
Not open for further replies.

moham

Programmer
Nov 12, 2001
13
0
0
US
I have a html page with a link on it:

<a href=&quot;javascript:win()&quot;>test</a>

The win() function is scripted as follows:

function win()
{
win=window.open(&quot;}

First time I click on the link the window opens. When I close the opened window and click on the link again nothing happens, unless I refresh the page again. I am using IE 5.5
 
It is at the end of the yahoo url in the window.open method.
 
first,
you did not actually correct your typo.
second, your code looks fine to me with one exception - you name 3 different things with the same name i.e &quot;win&quot;
imagine a room where there are 3 guys named John sit. So if somebody calls Jahn, how will these guys know which one of them is called?
do NOT give same nam to different objects!!!
try something like
function open_win()
{
   win=window.open(&quot; &quot;the_win&quot;);
} --------------------------------------------------
Goals are dreams with deadlines
 
dang yell...(above post)

anyway, check out this post...

thread216-231392

i just responded to another typo prob. why is there a ; automatically added? see the post above for another example.

- spewn

 
I'm not sure, but could this be because you are using the same variable to store a window Object, and a function? Before clicking the link, win points to the function. Once clicked, win points to a Window object. Try instead:
Code:
function win() {
    myWindow = window.open(...); myWindow.focus();
}
Cheers, Neil
 
Do not name your new windows the same thing. Using the same variable to reference the new window doesn't have anything to do with it. The second parameter that you pass to the open() function defines which name the new window bears. simply, don't pass this variable and it will never open in that window again.

Try this:

function win(myURL) {
open(myURL);
}

For modularity, you pass the URL to the function.
bluebrain.gif
blueuniment.gif
 
HAH... I didn't notice.
calling function win(), you might as well just call function open(). haha I'm so stupid X-)

If you want function win() to open a specific URL, then go ahead and do that. The point is, just don't pass any second parameter to it. Doing so will make the new page load into the same window.

Hope this helps :)
bluebrain.gif
blueuniment.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top