Creating an inline function in JavaScript for an anchor tag

I'm attempting to open a new window with a specific URL while also sharing the current page's address through an inline function. Here's what I have so far:

a href="javascript:void(0);" onClick='(function()
{
    var link = string.concat("example.com/UserStatus.phpid=99244613&utm_source=",window.location.href);
    console.log(link);
});return false;'>click here</a>

Unfortunately, nothing seems to be working as expected. Can anyone provide some assistance?

Answer ā„–1

Instead of using string.concat in your code, it is recommended to use "".concat:

function fun(){
  var link = "".concat("example.com/UserStatus.phpid=99244613&utm_source=", window.location.href); 
  console.log(link); 
}

fun();

The output will be:

example.com/UserStatus.phpid=99244613&utm_source=https://playcode.io/

For HTML:

<a href="javascript:void(0);" onClick='fun();'>click here
</a>

Simply replace string.concat with "".concat in your code.

Answer ā„–2

Everything is functioning perfectly.

<a href="javascript:avoid(0);" onClick="(function(){
   var link = ''.concat(`sample.com/UserStatus.phpid=99244613&utm_source=`,window.location.href); console.log(link);
   return false;
   })();return false;">tap here
</a>

Accessible Codepen Connection

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

`Failure to prompt an error following an unsuccessful post request in a node.js application using axios and express`

I'm currently facing an issue while trying to implement password change validation. The problem lies in not receiving the errorMessage from the server in case of an error. Although I've successfully managed to update the password and send back a ...

If the condition is true, apply a class with ng-class when ng-click is triggered

I am facing a situation similar to toggling where I am adding the class col-xs-6 to divide the page into two views. Initially, when I click, I set a variable value as true and in ng-class, I check for a condition to append the col-xs-6 class. Below is the ...

Having trouble with creating a new Next.js app using the latest version with npx?

Having some difficulty with the "npx create-next-app@latest" command while setting up Next.js. As a newcomer to both the community and Next.js, I could use some assistance in resolving this problem. Upon running the command, an unfamiliar message was displ ...

Generating hierarchical structures from div elements

Looking for guidance on how to parse a HTML page like the one below and create a hierarchical Javascript object or JSON. Any assistance would be much appreciated. <div class="t"> <div> <div class="c"> <input t ...

What is the reason for the visibility of my API key when utilizing next.js alongside environment variables?

I recently went through the next.js documentation and implemented a custom API key on my now server. However, I encountered an issue where when I execute now dev and navigate to the sources tab, my API key is visible. https://i.stack.imgur.com/kZvo9.jpg ...

Menu changes when hovering

I want to create an effect where hovering over the .hoverarea class will toggle the visibility of .sociallink1, .sociallink2, and so on, with a drover effect. However, my code isn't working as expected. Additionally, an extra margin is automatically ...

The responseText array is encountering parsing issues

Utilizing ajax, I am retrieving a json_encoded array from my PHP parser. The responseText returned is ["4.wav","2.wav","3.wav","6.mp3","1.mp3","5.wav"] If I place this into an array like so: var myArray = ["4.wav","2.wav","3.wav","6.mp3","1.mp3","5.wav" ...

The video on Videojs fails to show up on the screen

Currently utilizing the most recent version of videojs. Referencing this example http://jsfiddle.net/swinginsam/NWbUG/#share Access source code Having trouble identifying the issue. <!DOCTYPE html> <html> <head> <title>Video.j ...

Leveraging AJAX for connectivity to the Twitter API

Considering incorporating Twitter functionality into my web application, I decided to conduct some tests. After researching how to call the search Twitter URL (more information available at: ) in order to retrieve tweets containing specific words or phrase ...

Exploring the functionality of the readline module using a simulated command-line

I am currently working on developing a unit test for a module that utilizes the "readline" functionality to interpret standard input and provide standard output. Module: #!/usr/bin/env node const args = process.argv.slice(2) var readline = require(' ...

AngularJS $q - pausing execution to synchronize all promises

I've encountered a challenge that I haven't been able to solve through online searches. In my project, I am using a library for selecting items and performing custom modifications through callback functions. However, I need to execute some async ...

The correct method for accessing descendants in THREE.js in the latest version, r68

As of the release r68, the getDescendants() method has been removed from the THREE.Object3D API. How should we now achieve the same functionality without any warning message being provided? ...

Display Google Maps and YouTube videos once user consents to cookies

I recently installed a plugin on my WordPress site called Cookie Notice, which I found at this link. So far, I've been impressed with how user-friendly and lightweight it is. Due to the latest GDPR regulations, I now need to figure out a way to hide ...

React's `setState` function seems to be failing to hold onto

Recently, I've been challenged with creating an infinite scroll loader component. However, I'm facing a peculiar issue where my 'items' array is constantly resetting to [] (empty) instead of appending the new results as intended. A cou ...

Moving a Ball Back and Forth Using Three.js

Iā€™m looking to create a continuous motion for a Ball in Three.js, where it moves to the right, returns to its starting position, and then repeats the sequence. var geometry = new THREE.SphereGeometry( 5, 32, 32); var material = new THREE.MeshPhongMateri ...

Automatically fill in input fields in a form by selecting options from a dropdown menu and extracting data

After executing a MySQL query, a select dropdown menu is populated with data like this: <form method="post" action="action.php"> <select name="elements" id="elements"> <option type="text" value="">Select an element to be modifie ...

send the value from the input field to the designated button - link the two buttons

My goal is to create a feature where users can click on a button within the map and open an external page in Google Maps with specific dimensions (500 X 600) and without the Menu bar, Tool bar, or Status bar. // Custom Button Functionality by salahineo ...

Searching for dates within a range on DataTables using CodeIgniter

Can someone assist me in displaying data within a selected date range? Here is the code snippet I have so far: Below is the code for displaying the data tables: View <div class="box-body"> <div class="table-responsive"> ...

What is the best way to access the element before and after a specific element in an array using JavaScript?

I need to create a function that accepts a string input, searches for its match in an array, and then returns the previous and next elements in the array. const array = [ "11111", "22222", "343245", "5455", "34999", "34 ...

While attempting to use $scope.$apply() in Angular, I encountered a bug that

I have set up a specific example in a jsbin: http://jsbin.com/deqerelita/1/ Situation The concept is quite straightforward. You click a button, the controller adds to the model, and the view updates accordingly with a hidden input type="file". After the v ...