0

I've a pop-up that can be called trough a link. The problem is that i need to call it onload, an I can't find a way to do this.

This is the code of the pop-up

   <a href="https://sloways.leadpages.co/leadbox/14169a873f72a2%3A14f192411746dc/5636318331666432/"
    target="_blank">Click Here to Subscribe</a>
    <script data-leadbox="14169a873f72a2:14f192411746dc"
    data-url="https://sloways.leadpages.co/leadbox/14169a873f72a2%3A14f192411746dc/5636318331666432/"
    data-config="%7B%7D" type="text/javascript"
    src="https://sloways.leadpages.co/leadbox-1483020619.js">
    </script> 

I've tried to trigger the "Click Here to Subcribe" in different ways, like the following, without success:

  1. Jquery how to trigger click event on href element
  2. jQuery(document).ready(function(){
    jQuery("#add_redirect").trigger('click'); });
  3. Window.location.href (this open the link but in another page, not as a pop-up)

UPDATE N.1
I've bypassed the problem loading the pop-up URL through the <object> tag. I've put the <object> inside a Bootstrap modal so it still works like some kind of pop-up.

Community
  • 1
  • 1
Maxxd
  • 21
  • 1
  • 4

3 Answers3

1
<html>
<head>
<script data-leadbox="14169a873f72a2:14f192411746dc"
    data-url="https://sloways.leadpages.co/leadbox/14169a873f72a2%3A14f192411746dc/5636318331666432/"
    data-config="%7B%7D" type="text/javascript"
    src="https://sloways.leadpages.co/leadbox-1483020619.js"></script>
<script>
var displayPopup = function(){
 var element = document.getElementById('popUp');
 element.click();
}
</script>
</head>
<body onload="displayPopup();">
  <a href="https://sloways.leadpages.co/leadbox/14169a873f72a2%3A14f192411746dc/5636318331666432/" id="popUp"
    target="_blank">Click Here to Subscribe</a> 
</body>
</html>

I am using plan JS. When body JS object is completely formed or in other words when body's content is completely loaded then onLoad event is fired . I wired a displayPopup function to this event.

In displayPopup function i retrieve the anchor tag and manually click it .

varunsinghal65
  • 508
  • 4
  • 19
0

Use this following code

jQuery=jQuery.noConflict();
jQuery(document).ready(function(e){
   e.preventDefault();
   jQuery("#add_redirect").click(); 
});
Prashanth Reddy
  • 197
  • 2
  • 12
0

The solution by @Prashanth Reddy should work if you have jQuery loaded on your page.

For a simple implementation using plain javascript, you'll need to change the target attribute on your tag to '_self' from '_blank'. This will open the popup in your existing page instead of a new page.

then add the following at the end of the body section of your html:

<script>
  (function() {
    document.getElementById('add_redirect').click();
  })();
</script>

see here for a working example: jsfiddle

If you want to avoid inline script tags, you'll need to add an event listener to your javascript code. Here is a good starting point for how to do that:

plain js equivalent to jquery $.ready

Community
  • 1
  • 1
cadair
  • 31
  • 5
  • Using just this line: "document.getElementById('add_redirect').click();" triggers the link, but it opens a new page at the following link, instead showing a pop-up. "https://sloways.leadpages.co/leadbox 14169a873f72a2%3A14f192411746dc/5636318331666432/" Thank you – Maxxd Jan 11 '17 at 09:52