Your issue is your code will never execute.
$("#sem-seo").click(function() {
//THIS LINE CAUSES A NEW PAGE TO LOAD
window.location.assign("portfolio.html#anchor2");
//THAT MEANS THIS CODE WILL NEVER BE REACHED
$(window).bind("load", showAndScroll(1, 2));
});
You need to apply your code on the destination page, you can't execute javascript code for any page except the one you are on.
Also, don't attach handlers within handlers. If someone repeatedly clicks on #sem-seo
, you will attach multiple load
handlers to your window
, which is not what you want.
UPDATE
I think this will resolve your issue. On your origin page, add this to the link:
<a id="sem-seo" href="portfolio.html#anchor2?show=true" title="">LINK!</a>
And on your destination page, add this script:
$(function(){
var url = window.location.href;
if(url.indexOf('?show=true') != -1 || url.indexOf('&show=true') != -1)
$(window).bind("load", showAndScroll(1, 2));
});