1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Have HTML link just activate Javascript on current page ...

Discussion in 'HTML & JavaScript' started by OTrap, Apr 1, 2011.

  1. OTrap

    OTrap Jr. VIP Jr. VIP

    Joined:
    Jul 12, 2008
    Messages:
    2,293
    Likes Received:
    1,052
    Gender:
    Male
    Hey, I was looking for a way to do this before, but I let it fall to the end of the to-do list. Well, it's back to the top. :D

    In essence, here's what I'm hoping to do:

    Person is on a message board topic (the board has HTML enabled) we'll call Page A.
    They click a link to Page B (hosted on a different server and all), but all Page B does is execute a Javascript code on Page A, so that the browser just shows Page A, but with the Javascript funtion now active.
     
  2. captchaman

    captchaman Junior Member

    Joined:
    Sep 16, 2010
    Messages:
    190
    Likes Received:
    842
    Occupation:
    Software Programmer
    Location:
    USA
    Not sure I understand completely, but webbrowser will execute JS you'll just have to hack up the JS a bit.
     
  3. Stalli0n

    Stalli0n Junior Member

    Joined:
    Nov 17, 2010
    Messages:
    115
    Likes Received:
    83
    Location:
    Europe
    Found on another forum:
    Page A:
    Code:
      var newWin = window.open("pageB.aspx");  // ref to pageB
    
    newWin.onload = function () 
    {
             newWin.helloB();
    }
    
    function helloA()
    {
             // Run the alert method inside the new window
             newWin.alert("Hello from page A!");
    }
    
    page B:
    Code:
      var opener = window.opener; // Ref to pageA is stored in var opener
    opener.helloA(); // call to opener's helloA function
    
    function helloB()
    {
             // Run the alert method inside the opener window
             opener.alert("Hello from page B!");
    }
    
    // We can do the same thing in an event that occurs on this page
    var btn = document.getElementById("pageBButton");
    
    btn.onclick = function ()
    {
             window.opener.helloA();
    }
    
     
  4. Autumn

    Autumn Elite Member

    Joined:
    Nov 18, 2010
    Messages:
    2,197
    Likes Received:
    3,041
    Occupation:
    I figure out ways to make money online and then au
    Location:
    Spamville
    You're going to have difficult getting this to work across two different domains because of the limited javascript same origin policy.