Link to home
Start Free TrialLog in
Avatar of tmonteit
tmonteitFlag for Afghanistan

asked on

Can't trigger javascript from seperate page.

Beginner question.   I have 2 pages.  When I click on page 2 I want it to load page 1 AND execute javascript on the first page.  

The solution I tried is to use a hash (see code below:  Page 1 is 'puppies'.  Page 2 is 'index.html')

There is a live example running that demonstrates this problem:  

Go to http://107.22.173.10 then click Item 1.    This is the result "I like puppies" is I want to see when I click the hashed index.html
Then click "puppies" and click Item 1 from that page.   It should produce the same result but it doesn't

Link to the Page  http://107.22.173.10
Link to the trigger I can't get working:  http://107.22.173.10/index.html#runFunction1

I know very basic javascript and I need some expert help debugging this.  Any ideas what is happening here?   How can I achieve the functionality I want?
Page 1 Code:
<a href="index.html#runFunction1">Item 1: triggers index.html#runFunction1</a>

Page 2 Code:
 function showItem1() {
         $("txtCtr").update("<h2>Item 1</h2> <p>I like puppies.</p>");
      }
        
      if (window.location.hash == '#runFunction1') {
          showItem1();
      }

Open in new window

Avatar of COBOLdinosaur
COBOLdinosaur
Flag of Canada image

You can't use a link to target a function on another page.


Cd&
ASKER CERTIFIED SOLUTION
Avatar of nap0leon
nap0leon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tmonteit

ASKER

The trigger worked perfect!  Thanks a bunch.  Unfortunately the code failed for another reason.  I will ask a separate question.