Easily automate button clicks on a new tab website

Seeking assistance below, following codes are sourced from "example.com" as assumed:

<a href="http://www.example.org" target="vo1" onclick="gp(1)" rel="nofollow">Click Me</a>

Upon clicking on "Click Me", the function "gp()" will be executed

<script>
function gp(pul){
    var qal = "vo";
    var tul = document.querySelectorAll('[target="'+qal+pul+'"]');    

    [].slice.call(tul).forEach(
        function(link){
            setTimeout(function(){
                if(pul == 1){
                    window.open("http://www.example.com",qal+pul);

                }else
                if(pul == 2){
                    window.open("http://www.example.com",qal+pul);
                }
            },1000);
        }
    );
}

</script>

Which script should be added in the above code to automatically click on "testbutton" when "example.com" is loaded in a new tab? The trigger pop out message should appear in the new tab.

The below codes pertain to the pop out message.

<button style="display:none;" id="myBtn">testbutton</button>

<div id="myModal" class="modal">

  <!-- Modal content -->
  <div class="modal-content">
    <div class="modal-header">
      <span class="close">&times;</span>
      <h2>Modal Header</h2>
    </div>
    <div class="modal-body">
      <p>Some text in the Modal Body</p>
      <p>Some other text...</p>
    </div>
    <div class="modal-footer">
      <h3>Modal Footer</h3>
    </div>
  </div>

</div>

<script>
// Get the modal
var modal = document.getElementById("myModal");

// Get the button that opens the modal
var btn = document.getElementById("myBtn");

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

// When the user clicks the button, open the modal 
btn.onclick = function() {
  modal.style.display = "block";
}

// When the user clicks on <span> (x), close the modal
span.onclick = function() {
  modal.style.display = "none";
}

// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
  if (event.target == modal) {
    modal.style.display = "none";
  }
}
</script>
<style>
body {font-family: Arial, Helvetica, sans-serif;}

/* The Modal (background) */
.modal {
  display: none; /* Hidden by default */
  position: fixed; /* Stay in place */
  z-index: 1; /* Sit on top */
  padding-top: 100px; /* Location of the box */
  left: 0;
  top: 0;
  width: 100%; /* Full width */
  height: 100%; /* Full height */
  overflow: auto; /* Enable scroll if needed */
  background-color: rgb(0,0,0); /* Fallback color */
  background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}

/* Modal Content */
.modal-content {
  position: relative;
  background-color: #fefefe;
  margin: auto;
  padding: 0;
  border: 1px solid #888;
  width: 80%;
  box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
  -webkit-animation-name: animatetop;
  -webkit-animation-duration: 0.4s;
  animation-name: animatetop;
  animation-duration: 0.4s
}

/* Add Animation */
@-webkit-keyframes animatetop {
  from {top:-300px; opacity:0} 
  to {top:0; opacity:1}
}

@keyframes animatetop {
  from {top:-300px; opacity:0}
  to {top:0; opacity:1}
}

/* The Close Button */
.close {
  color: white;
  float: right;
  font-size: 28px;
  font-weight: bold;
}

.close:hover,
.close:focus {
  color: #000;
  text-decoration: none;
  cursor: pointer;
}

.modal-header {
  padding: 2px 16px;
  background-color: #5cb85c;
  color: white;
}

.modal-body {padding: 2px 16px;}

.modal-footer {
  padding: 2px 16px;
  background-color: #5cb85c;
  color: white;
}
</style>

The concept is as follows: while in urlA, clicking on a link triggers the loading of urlA in a new tab. Upon this new tab load, an automatic click on the button triggers the appearance of the pop-out message. Appreciate your help in advance.

Answer №1

Can you clarify what you mean by auto-click?

When the new tab opens, is it directing to a website that you created?


To achieve this, you can utilize URL parameters. I can provide you with a simple example which you can then enhance for more advanced functionality.

In HTML, you would use:

<a target="_blank" href="http://example.com/index.html?clickButton=true">Link</a>

The parameter "clickbutton=true" is included in the href link.

For JavaScript, you can write something like:

function buttonClick() {
alert('pop up')
}

let url = window.location.href;
let params = url.split('?');
let myparam = params[1].split('=');
if (myparam[1] === 'true') buttonClick();

I extracted the URL string and used split functions to retrieve the parameter value. While there are likely more efficient methods available, I provided this basic JS code as an example.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using jQuery and AJAX to prevent the default behavior of a link, initiate an AJAX request, and then navigate to the link afterwards

Attempting a seemingly 'simple' task has turned into quite the challenge for me. My goal is to have a user click a link, prevent the default action, execute an AJAX function, and then proceed to follow that link. So far, my attempts have only re ...

How many logical lines of code are in the Ubuntu operating system?

As I develop my web application, it is crucial for me to track the lines of code written in languages such as php, css, html, and JavaScript specific to the /var/www directory. However, when using the command line code counter tool, I find myself tempted ...

The form submits immediately after jquery is activated

One challenge I'm facing involves multiple forms on a single page being submitted using jQuery. Currently, I have the following code snippet: $("form").submit(function (e) { // Submit form via Ajax }); The problem arises when the form is only s ...

Retrieve information stored in a component's data variable

After creating a Vue repository using vue init webpack my-app My main.js file looks like this -- // The Vue build version to load with the import command // (runtime-only or standalone) has been set in webpack.base.conf with an alias. import Vue fro ...

What is the best way to achieve a seamless CSS transition for my sticky navigation bar?

Looking to create a sticky bar with a smooth CSS transition instead of the current rough effect. Any tips or hints would be greatly appreciated! For reference, I found the exact animation I'm aiming for on this website: https://css-tricks.com/ Here i ...

the countdown function could not access the inst variable

I found an amazing plugin at that I'm using. Currently, I have 3 countdown timers that are loaded with a json array. However, when I try to recharge them, they become blocked and the following error message pops up: TypeError: inst.options is undef ...

Tips for aligning text to the left instead of the right when it exceeds container width in IE 11

Within the div, there is text with a 5px margin on the right. When the container div narrows, the text overflows from the container and loses the right margin. Is it feasible to maintain this margin on the right side while allowing the text to overflow fro ...

The jQuery Ajax call is hitting the error callback even though the response shows a readyStatus of 4 and a status of 200

I am encountering an issue with my application that uses jQuery Ajax call. It works perfectly fine in IE9, Firefox, and Chrome. However, in IE 8, it triggers the error callback even when the response has a readyStatus of 4 and status of 200. Here is the r ...

Javascript Calculator with Dual Input Fields

I have been given a task to create a calculator by tomorrow using Javascript. Unfortunately, I am currently taking a distance course and Javascript has just been introduced in this assignment. While I am familiar with HTML and CSS, Javascript is something ...

Is it possible to include a base url for imports in React JS?

Conventional method for adding imports: import Sample from ‘../../../components/signup’ I want to simplify imports by removing the front dots and slashes: import Component from ‘components/signup’ Is there a way to set a base URL for imports to ...

Having difficulty with express.index when trying to send a JSON object

Express is my tool of choice for creating a simple web page. The code in my index.js file looks like this: exports.index = function(req, res){ res.render( 'index', { title: 'Expressssss', Tin: va ...

Is it possible to update the CSS file of an external SVG file in real-time?

Is there a way for an SVG image to reference another CSS file? A webpage contains an SVG file. A button allows users to switch between classic colors and high contrast mode on the entire webpage, including the SVG image. Attempt w.css (white backgrou ...

Selecting elements dynamically with JQuery

Trying to use a jQuery selector within plugin code created by a 3rd party has proved difficult. When hardcoded, it works fine; however, when attempting to use variables for dynamic selection, the object cannot be found. The lack of id handles in the CSS c ...

The process of including or excluding an item in an array

There are 2 toggle buttons. If the value is true, it will be added to the array, otherwise the element will be removed. data: originality: [] toggles: <toggle id='1' ref='toggleOriginal'> Click </toggle> <toggle id=&apo ...

Struggling with pagination problems in Bootstrap 4 and looking to integrate QR code functionality into your blade template?

I am currently facing an issue with generating a batch of QR codes using the SimpleQR code generator in Laravel blade template on the fly for printing. The problem arises when a page break occurs, as it breaks the QR code. I attempted to use the break-insi ...

I'm baffled by the fact that my routes appear to be non-existent. I cannot comprehend the reason behind this issue

I'm fairly new to web development, and I've been struggling with this issue for the past hour. Even after simplifying my code to the bare minimum, it's still not working. Here's what I have so far: app.js: const express = require(&apo ...

Incorporating a technique for aligning text towards the right as the number of characters or digits expands

I'm designing a game user interface with a money indicator. Let's imagine the player has 0 dollars in their wallet, it should appear like this: https://i.stack.imgur.com/35eoh.png Please note that it is located in the upper right corner. The p ...

Implementing a configuration file into a client-side web application using asynchronous methods

Currently, I am facing a challenge with an SPA that is being developed using various custom components from different sources. The main issue at hand is how to initialize certain settings (such as Endpoint URLs) using a settings file that can be configure ...

What is the best way to add controllers to AngularJS?

What is the best way to troubleshoot this setup? app.js var app = angular.module('app', ['ui.router', 'app.controllers']); /* Why is FooCtrl not being recognized here? */ controllers.js var controllers = angular.module(&a ...

Error Handling for Ajax Functions Not Triggering

I have a function that works perfectly when there are results to display. However, I want a message to show up for "No Results" if there are no program host records to display. But currently, nothing happens in that case. Any suggestions? Thank you for you ...