0

Is it possible to have an onclick event happen after a page redirect? I have my Java files setup so there is a smooth scroll to "anchor2" after loading the new page but I can't for the life in me find a way to get the onclick function (Another java) to work on the new page.

<a href="portfolio.html#anchor2" onclick="javascript:showAndScroll(1, 3)" title="">Link</a>

The following works on the portfolio.html page to open/close sections onclick

 <a onclick="javascript:showAndScroll(1, 3)" title="">Link</a>

But I want this functionality when on a different page to portfolio so that it links to portfolio.html and the ID (smooth scrolls to #anchor2) and then the onclick even to happen?

Here is the Fiddle

Is this possible?

3
  • Use onload and read the hash. Also no need for the javascript: pseudo protocol Commented Dec 30, 2013 at 12:18
  • 1
    Try putting parameters in the query string. And, then on redirect, read the query string parameter value and take appropriate action. Commented Dec 30, 2013 at 12:18
  • You can see a fiddle of the general idea on this older post. stackoverflow.com/questions/20838287/… Commented Dec 30, 2013 at 12:19

1 Answer 1

2

You are looking the problem the wrong way.

You cannot create an event for "After new page load", but you can do "After page load".

So, try to catch your anchor on page load and there execute your function.

Sign up to request clarification or add additional context in comments.

2 Comments

This question is in regards to this fiddle (the footer links) jsfiddle.net/veT6z/48 Dont think catching my anchors will work with the slider method used?
Just tried this, $("#sem-seo").click(function(event){ window.location.replace("portfolio.html#anchor2"); $(document).ready(showAndScroll(1, 2)); }); and it did not work

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.