-4

I have a page (page 1) that has one link. (Link A) This link when clicked opens a Picture gallery on the same page.

I have another page (page 2) that has another link (Link B) This link opens page 1.

What I want to do is: I want link A to be clicked automatically. Immediately page 1 is opened.

So basically, what happens is once you click Link B a Picture Gallery opens.

Is there any HTML code that makes a link run immediately (automatically) the page is opened?

Thank you!

user4171112
  • 47
  • 1
  • 7

2 Answers2

0

You can use the window.location methods replace or href

// js redirect
window.location.replace("http://somesite/somepage");

//same clicking on a link
window.location.href = "http://somesite/somepage";
Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268
0

If i understand, you need to force the click on the link to open the gallery when the page1 is loaded with JavaScript (you can replace the first parameter of the function and get the object of the link with other ways):

document.addEventListener("DOMContentLoaded", function(event) { 
  eventFire(document.getElementById('myLinkId'), 'click');
});

function eventFire(el, etype){
  if (el.fireEvent) {
    el.fireEvent('on' + etype);
  } else {
    var evObj = document.createEvent('Events');
    evObj.initEvent(etype, true, false);
    el.dispatchEvent(evObj);
  }
}

Source: How to simulate a click with JavaScript?

With JQuery this is a pretty easy:

$(document).ready(function(){
    $('#myLinkId').click();
});
Community
  • 1
  • 1
mucadoo
  • 26
  • 5