View Full Version : link to open page AND call function?

10-27-2006, 10:46 PM
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!

10-28-2006, 07:12 PM
This is how you can auto launch a function at page load.

window.onLoad = function() {
alert("this is launching at load");

fucntion myfunction() {
alert("This too!");

10-29-2006, 10:10 AM
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>

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).

10-31-2006, 04:02 PM
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!

10-31-2006, 04:04 PM
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!