locked
Accessing functions via multiple pages RRS feed

  • Question

  • Hi,

    I have a Navigation type app with multiple pages and would like to access a global function via any of the pages (or to access a function specified in the Javascript for any individual page from the Javascript for another page).

    Is this possible? If so, how?

    Thanks, S

    Saturday, November 3, 2012 11:22 PM

Answers

  • Hi sarrowsmith,

    I think you can use WinJS.Namespace.define to declare some global objects (with properties and functions). And you can put the declaration code in the .js file of the default.html page (which is loaded at beginning) so that other sequential page loaded (in your Navigation App) will also be able to use the declared global objects.


    #WinJS.Namespace.define function
    http://msdn.microsoft.com/en-us/library/windows/apps/br212667.aspx

    #Organizing your code with WinJS.Namespace (Windows Store apps using JavaScript and HTML)
    http://msdn.microsoft.com/en-us/library/windows/apps/Hh967793.aspx

    Note, for a multi-page navigation windows store javascript app, all the javascript files (referenced in the main host page and other navigation pages) will be loaded into memory in order of the pages (which reference the script files) are loaded(navigated) in the application. And after the script is loaded, they will remain in memory even if you navigate away from the certain page (the same for the CSS style).

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help. Putting communities in your palms. Launch the browser on your phone now, type aka.ms/msforums and get connected!

    Monday, November 5, 2012 3:16 AM
    Moderator

All replies

  • Hi sarrowsmith,

    I think you can use WinJS.Namespace.define to declare some global objects (with properties and functions). And you can put the declaration code in the .js file of the default.html page (which is loaded at beginning) so that other sequential page loaded (in your Navigation App) will also be able to use the declared global objects.


    #WinJS.Namespace.define function
    http://msdn.microsoft.com/en-us/library/windows/apps/br212667.aspx

    #Organizing your code with WinJS.Namespace (Windows Store apps using JavaScript and HTML)
    http://msdn.microsoft.com/en-us/library/windows/apps/Hh967793.aspx

    Note, for a multi-page navigation windows store javascript app, all the javascript files (referenced in the main host page and other navigation pages) will be loaded into memory in order of the pages (which reference the script files) are loaded(navigated) in the application. And after the script is loaded, they will remain in memory even if you navigate away from the certain page (the same for the CSS style).

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help. Putting communities in your palms. Launch the browser on your phone now, type aka.ms/msforums and get connected!

    Monday, November 5, 2012 3:16 AM
    Moderator
  • Awesome, thanks Steven!

    Tuesday, November 6, 2012 2:42 AM