Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    <function> not defined

    Hello,

    A very easy question I hope.

    I get in Netscape javascript console the title error and "object expected" in IE error message, these on the same page, for the following code:

    "
    <HTML>
    <HEAD>
    <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
    <TITLE>Thanks</TITLE>
    <!--
    <SCRIPT type="text/javascript">

    function RedirectMe(id)
    {

    if (window.navigator.appName == "Microsoft Internet Explorer")
    {
    alert("in RedirectMe()");
    alert(id);

    window.location.href = ID


    }
    else
    {
    window.alert("in RedirectMe()");
    window.alert(id);

    alert("window.navigator.appName = " & window.navigator.appName);
    window.close();
    window.open(id);

    }

    }

    function test()
    {
    alert("test");
    }

    function myfunction(txt)
    {
    alert(txt)
    }

    </SCRIPT>
    -->
    </HEAD>

    <BODY>
    ....
    <table><tr><center>
    <!--<td><a id = 'http://cerospig.ocean.org.il/' href = # style = 'color:blue;' onclick = "window.alert(this.id); javascript:RedirectMe('this.id');">Cerospig Home Page</a></td>-->
    <!--<td><a id = 'http://cerospig.ocean.org.il/' href = "javascript:test();" style = 'color:blue;'>Cerospig Home Page</a></td>-->
    <td><a id = 'http://cerospig.ocean.org.il/' href = # style = 'color:blue;' onclick = "test();">Cerospig Home Page</a></td>
    <td></td><td></td><td></td>

    <!--<td><a id = 'http://www.ifremer.fr/mama/' href = # style = 'color:blue;' onclick = "window.alert(this.id); javascript:RedirectMe('this.id');">MAMA Project</a></td>-->
    <!--<td><a id = 'http://www.ifremer.fr/mama/' href = "javascript:test();" style = 'color:blue;'>MAMA Project</a></td>-->
    <td><a id = 'http://www.ifremer.fr/mama/' href = # style = 'color:blue;' onclick = "test();">MAMA Project</a></td>
    </center></tr></table></p>
    </DIV>
    </BODY>
    </HTML>

    "

    The comments are for the deferent trials.
    Basically I try to redirect each browser to the same two links.
    but even test() function is not working.

    I'm puzzled. What is wrong?

    thanks for your attention

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    The whole script is inside the comment tag.

    <!--
    <SCRIPT type="text/javascript">
    ...
    </SCRIPT>
    -->

    Is that also included in the trials?

    But you don't need the id, you can put the url in the href. That way, the link will still work even if javascript is disabled.
    Code:
    <a href="http://cerospig.ocean.org.il/" style="color:blue;" onclick="return RedirectMe(this.href);">Cerospig Home Page</a>
    ...
    <script type="text/javascript">
    function RedirectMe(url)
    {
         if (window.navigator.appName == "Microsoft Internet Explorer"){
             location.href = url;
         }
          else {
             var w = window.open(url);
             w.focus();
         }
         return false; //cancels link action
    }
    </script>
    But I'm curious of that script. Why do you want to open the page differently in each browser?

  • #3
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Still some problems

    Thanks a lot Glenn for your fast answer,

    I've tried your solution.
    It links to the right places but:

    Using IE ther's still "Object expected" error for the "RedirectMe('this.href')" command.
    Netscape javascript console still report an Error: <function> is not defined.

    The whole function codes are within the comment tags.

    The reason I tried to open them diferently is that my tests showed a deferent behavior for the two browsers (as expected) Netscape opened a new browser and left the old one opened. I wanted it to be closed.

    Thanks a lot again!!!

    Sigal

  • #4
    Regular Coder
    Join Date
    Nov 2002
    Location
    Manchester, UK
    Posts
    533
    Thanks
    4
    Thanked 1 Time in 1 Post
    try changin

    window.location.href = ID

    to

    window.location.href = id

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    Did you remove the comment tags that enclose the <script> tag?

    <!--
    <SCRIPT type="text/javascript">
    ...
    </SCRIPT>
    -->

    That comments out the whole script as if your functions never exist.

  • #6
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Remove the single quotes surrounding this.href

    RedirectMe('this.href')

  • #7
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    hi again

    Thank you all,

    Indeed the comment tags were in the way.
    I've missplaced them.

    Removing the single quotes surrounding this.href
    made it link more smoothly.

    sigal


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •