Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

218
Vistas
Why does Copy button copy 'undefined' instead of copying value from html dom?

I'm trying to make my own user script for https://mlwbd.ltd/movie/don-2022

I wish to copy the value of specified hidden input

preTag = document.getElementsByName("FU");
p = preTag[0];
console.log(p);

Ekra = document.getElementsByClassName("linktabs");
q = Ekra[0];
console.log(q);

function copy(ele) {
    let temp = document.createElement('textarea');
    document.body.appendChild(temp);
    temp.value = ele.textContent;
    temp.select();
    document.execCommand('copy');
    temp.remove();
}

btn = document.createElement("button");
btn.innerHTML = "copy"
btn.onclick = function(){
    copy("p");
};

q.insertBefore(document.createElement("br"), q.childNodes[0])
q.insertBefore(btn, q.childNodes[0])

The Html code is

input type="hidden" name="FU" value="https://songslyric.site/links/46905/" 
I want to copy the Value of name="FU" when I click the button. The code I pasted is created from google chrome snippets. Please help me.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

This will get you started:

// ==UserScript==
// @name         mlwbd.ltd
// @namespace    http://tampermonkey.net/
// @version      0.1
// @match        https://mlwbd.ltd/movie/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    const $ = document.querySelector.bind(document);

    $('body').insertAdjacentHTML('beforeend', init_css() );

    setTimeout(() => {
        $('#mybutt').addEventListener('click', () => {
            //alert('hi');
            const fu = $('#download table form input[name=FU]');
            //console.log(fu.value);
            copy2clip(fu);
        });
    },500);


})();
function init_css(){
    return `
    <button id="mybutt">Copy2Clip</button>
    <style id="myInitCss">
        #mybutt{position:absolute;top:90px;left:45%;height:30px;width:120px;}
        #mybutt{background:#0073ea;color:white;padding-top:5px;text-align:center;}
        #mybutt{z-index:99999;}
    </style>
    `;
}
function copy2clip(ele) {
    let temp = document.createElement('textarea');
    document.body.appendChild(temp);
    temp.value = ele.value;
    temp.select();
    document.execCommand('copy');
    temp.remove();
}

Notes:

  1. Despite the $ character, this code is not jQuery (it is vanilla javascript)
  2. You can uncomment the alert() and console.log to see how things are working at that point.
about 4 years ago · Juan Pablo Isaza Denunciar

0

Try this on your other question:

    // ==UserScript==
    // @name         adsgo.digital
    // @namespace    http://tampermonkey.net/
    // @version      0.1
    // @include        https://adsgo.digital/
    // @include        https://adsgo.digital/*
    // @grant        none
    // ==/UserScript==

    (function() {
        'use strict';
        const $ = document.querySelector.bind(document);

        $('body').insertAdjacentHTML('beforeend', init_css() );

        setTimeout(() => {
            $('#mybutt').addEventListener('click', () => {
                //alert('hi');
                const fu = $('.posts-dynamic.posts-container form input[name=FU6]');
                //console.log(fu.value);
                copy2clip(fu);
            });
        },500);


    })();
    function init_css(){
        return `
        <button id="mybutt">Copy2Clip</button>
        <style id="myInitCss">
            #mybutt{position:absolute;top:90px;left:45%;height:30px;width:120px;}
            #mybutt{background:#0073ea;color:white;padding-top:5px;text-align:center;}
            #mybutt{z-index:99999;}
        </style>
        `;
    }
    function copy2clip(ele) {
        let temp = document.createElement('textarea');
        document.body.appendChild(temp);
        temp.value = ele.value;
        temp.select();
        document.execCommand('copy');
        temp.remove();
    }

Notes:

  1. You can compare this answer to the previous one and you'll notice that only one line has changed.

  2. The topic to study to understand how to reference the HTML scaffolding as I did is called: "CSS Selectors". The JavaScript querySelector() directive uses CSS selectors to specifically target the desired HTML tag.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda