...

View Full Version : <function> not defined



sigal
06-22-2004, 02:20 PM
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

glenngv
06-22-2004, 02:56 PM
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.


<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?

sigal
06-23-2004, 10:22 AM
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

homerUK
06-23-2004, 10:29 AM
try changin

window.location.href = ID

to

window.location.href = id

glenngv
06-23-2004, 10:38 AM
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.

Willy Duitt
06-23-2004, 11:03 AM
Remove the single quotes surrounding this.href

RedirectMe('this.href')

sigal
06-23-2004, 11:45 AM
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 :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum