0

My imagebutton will not cause the popup window to appear when its clicked. Here is my code.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script type="text/javascript">
    function goToAddNewsletterAddPage() 
    {
        window.open("Newsletter.aspx","mywindow");
    }
</script>

    <asp:Image ID="Image1" runat="server" Height="87px" Width="158px" ImageUrl="~/images/signup.gif" onclick="goToAddNewsletterAddPage()"/>

1 Answer 1

1

If you look in the console of the browser, you should see a syntax error. Function declarations (the style you've used in your script) must have a function name, so there's a syntax error...

<script type="text/javascript">
    //    ...v-- here
    function () 
    {
        window.open("Newsletter.aspx","mywindow");
    }
</script>

Perhaps you meant:

<script type="text/javascript">
    function goToAddNewsletterAddPage() 
    {
        window.open("Newsletter.aspx","mywindow");
    }
</script>

(There is a different, but related, thing called a function expression, which doesn't have to have a function name [and due to IE bugs is usually better off without one], e.g.:

var x = function() { /* ... */ };

The key to knowing which is which is to look to see whether the function structure is being used as a right-hand value, e.g., the right-hand side of an assignment [=] or initializer [:], or being passed into a function as an argument. If it is, it's a function expression; if not, it's a function declaration.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.