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!

Problem with function I made.

Status
Not open for further replies.

MDiesel

Programmer
Sep 10, 2009
3
GB
Hey guys!! I have been a programmer in other languages for a year now. However, none have been web based. As a result I am learning javascript. You may not appreciate such a simple question... but I can't see my error... I have tried searching and finding alternatives to the problem, but have been unable to locate its roots. The function is a simple one, but one that could be useful to me later. The idea is that I have a simple code that will not be too long, that launches a confirmation box before taking the user to an external link:
Code:
    <script type="text/javascript">
    function _externallink(href)
    {
      if(confirm('About to open an external link. Continue?')=true)
      {
        window.open(href,'_Blank','',true)
      }
    }
    </script>

and then in the body it can be called as an anchor using:

Code:
<a href="javascript:_externallink('[URL unfurl="true"]http://www.google.com');">link</a>[/URL]

So far I can see that it launches the function, and the confirm box. So the problem is with opening the window. I have checked the params etc... so what am I doing wrong? or is it a problem with the browser notrecognizing the command? I doubt it! Firefox 3.5, winxp pro sp3

From what I can see you guys have a very nice setup here! Thanks a lot, and I hope I haven't been stupid!

MDiesel
 
Here:

Code:
 if(confirm('About to open an external link. Continue?')=true)

You are missing an = sign.

One Equal sign means assignment, two equal signs is comparison.


Code:
 if(confirm('About to open an external link. Continue?')=[red]=[/red]true)





----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Found it!!

you need a double equals in the if, and a colon on the window open statement.

MDiesel
 
realize that now phil, thanks a lot!

MDiesel
 
Hi

When you already have a boolean value why are you comparing it with another one just to get a third boolean ?
Code:
[b]if[/b] [teal]([/teal][COLOR=darkgoldenrod]confirm[/color][teal]([/teal][green][i]'About to open an external link. Continue?'[/i][/green][teal]))[/teal]

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top