Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Aug 2005
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    link to open page AND call function?

    I have a javascript that pulls data from an xml file. It is located on a sub page within my site. I'd like to know if I can create a link elsewhere on the site to open that particular page AND activate the function at the same time. Not sure if this is possible, and/or how to accomplish it. So for example, my page is called subpage.html which has all the working js and lets say a function to pull some of that data called 'articleDisplay'. So on subpage.html I could pull article 3 by creating this link: <a href="javascript:articleDisplay(3)">TITLE</a>, which works great... but, on index.html I want to include a direct link that will OPEN subpage.html and then call the articleDisplay function. I'm trying to accomplish this so that I can create an include on the index page that lists a few of the articles by their titles, instead of a simple link to 'click here to view news'... Thanks!

  • #2
    Regular Coder
    Join Date
    Dec 2002
    Location
    Minneapolis, MN
    Posts
    208
    Thanks
    0
    Thanked 1 Time in 1 Post
    This is how you can auto launch a function at page load.
    Code:
    <script>
    window.onLoad = function() {
    alert("this is launching at load");
    myfunction();
    }
    
    fucntion myfunction() {
    alert("This too!");
    }
    </script>
    anthony

  • #3
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    are you opening a new window when the link is clicked? if so and you can use a small script in the opened window such as :

    <script type=text/javascript>
    opener.YourFunction();
    </script>



    if the script is in the child window, and you want to call to the function from the parent window you must name the opened window and call to it by its name, much like you would if using frames (using target value).
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.

  • #4
    New Coder
    Join Date
    Aug 2005
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Brandon, no actually I want the link to open in the same window in the same browser. No popups or anything. Although if that's not possible then maybe a popup would be the route to go? Are we allowed to post links to sites (for examples) in this forum? Thanks!

  • #5
    New Coder
    Join Date
    Aug 2005
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ez4me, I can't use window onload to call the function because there are different parameters for each article. Since there are a number of different article numbers, and the function is displayArticle, if you click on the 3rd article link I want the script to change to the subpage.html page AND load the 3rd article (via the js). It would change depending on which article link was clicked. Thanks!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •