7

This is what the link looks like on page 1:

<li id="click1">
  <a href="products.htm#test4Handle1">TNT Cable System</a>
</li>`

This is what I want to trigger on page 2:

<a name="test4Handle1">
  <button onclick="$('#test4Handle1').click()">TNT Cable System</button>
</a>

my attempt at jquery

$("test4Handle1").observe('domready',function() {
  document.getElementById("test4Handle1").click();
});

What page should have the javascript page 1 or 2?

1
  • 1
    I think what are trying to do is simply not possible, at least in the way you are attempting it. You will need page one to set some sort of server side setting that page two can check. Commented Apr 23, 2013 at 8:03

3 Answers 3

3
+25

Check if this helps you. Following is one example I got working

Here is Page1.html

<!DOCTYPE html>
<html>
<head>
  <title>Page1</title>
</head>
<body>
  <h2>Page1</h2>
  <a href="page2.html?event=true">Click here to go on page2</a>
</body>
</html>

And here Page2.html

<!DOCTYPE HTML>
<html>
<head>
  <title>Page2</title>
  <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js" >   
  </script>
  <script type="text/javascript">
    $(function() { 
      var prevURL = (window.location.search).contains("event=true");
      if(prevURL == true)
        $("#btn_click").click();
      else
        alert("Not proper prev page");
     });
  </script>
</head>
<body>
  <h2>Page2</h2>
  <a href="page1.html">Click here to go on page1</a>

  <input type="button" id="btn_click" value="Test Button Click"/>
  <script>
    $("#btn_click").click(
       function() {
         alert("Button CLicked From jQuery");
       });
  </script>
</body>
</html>
Sign up to request clarification or add additional context in comments.

Comments

1

On Page 2, paste this code

$(document).ready(function(){
if(window.location.hash == "#test4Handle1"){
document.getElementById("test4Handle1").click();
}
});

Comments

0

If I understand you correctly, I would have to say that what you are looking for is not possible. Scripts are jailed to the pages on which they are loaded in. While it is possible for them to trigger the creation of new windows, it is not possible to interact with those windows, their DOM's and the scripts they are running.

2 Comments

Wow, upon reading the question, it does seem difficult to understand(it was kinda late and i had been hitting my head against a wal for a while). My apologies, so as clarification. Page 1 has a link to an anchor on page b, there is content on a jquery slider that activates with a click() trigger on page b, I would like to have the link on page a go to page b and trigger the click on the specific content to make the specific slide show. Is there any way to do this with jquery?
@allingeek Your statement is incorrect. What you are saying is only applicable for different domains. Child windows of the same domain can access their parents and vice versa. See: stackoverflow.com/questions/16133643/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.