0

I am brand new to JavaScript so bear with me. I have a JavaScript function that is on my page:

<script type="text/javascript">
    Sys.debug = true;
    var popup;
    Sys.require(Sys.components.popup, function () {
        popup = Sys.create.popup("#popup", {
            parentElementID: "target",
        });
    });
</script>

It works perfectly when I use it as an event:

<input type="button" onclick="popup.show()" value="Edit Theme" style="float: right; margin-right: 7.25em;" />

I want to call it on page load, inside the body tag I have the following code:

<script>
    window.onload = popup.show;
</script>

The method does not appear to get called. What am I doing wrong?

6
  • 2
    Try : window.onload = popup.show; Commented Aug 12, 2013 at 18:31
  • I would open up your browsers developer kit to view your JavaScript step by step as it runs on your page. Check the console for error messages, it may lead you directly to the problem. Commented Aug 12, 2013 at 18:33
  • Error message: Uncaught TypeError: Cannot read property 'show' of undefined Commented Aug 12, 2013 at 18:38
  • what is the order of the script tags on the page? Commented Aug 12, 2013 at 18:39
  • Is this Sys.require ASP.Net script loader? If it is you need to show the pop up when the script has loaded. Commented Aug 12, 2013 at 18:39

2 Answers 2

2

Based on the documentation on Sys.Require, it seems that Sys.Require is called on load, which means that based on the ASP.Net page lifetime the script hasn't loaded when the onload event fires.

It looks like you can use Sys.onReady() instead:

Sys.onReady(function(){
    popup.show();
})
Sign up to request clarification or add additional context in comments.

Comments

2

You should write:

window.onload = popup.show;

2 Comments

@DavidTunnell is Sys.require asynchronous?
I don't know. I used a tutorial to make the inline popup.. I'm looking for it now...

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.