Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q210 I keep receiving function undefined in the following script, why?

irt.org | Knowledge Base | JavaScript | Misc | Q210 [ previous next ]

Q210 I keep receiving function undefined in the following script, why?

<html>
<head>
<base target="_top">

<script language="JavaScript"><!--
function myfunction() {
    alert("Hello World!");
}
//--></script>
</head>

<body>

<a href="javascript:myfunction()">some link text<\/a>

</body>

Because of the BASE tag in the head of the document, the link is targeting the URL javascript:GetLoc() into the _top window. If the _top window does not contain a JavaScript function called myfunction() then an error message will appear.

Visualise the URL as: javascript:_top.myfunction(), and you'll see why it fails.


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.