最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - alert() doesn't show the value in a Tampermonkey script - Stack Overflow

matteradmin8PV0评论

I'm trying to make a Tampermonkey script to unhide one DIV defined like that

<div id="div2" style="display: none;"> 

My script doesn't work and I don't know why...

// ==UserScript== 
// @name            Actualisation Vérification Infra 
// @namespace       / 
// @version         0.1 
// @description     Permet de recharger la page toutes les x millisecondes afin de garder la session active 
// @match           .do* 
// @copyright       2013+, The PCU Team 
// ==/UserScript== 

var extern = document.getElementById('div2').style.display; 
alert('extern'); 

// Refresh toutes les xx minutes  
var delay = "30m"; // Remplacer par le temps souhaité, 1s, 10s, 60s, 1m, 15m, 30m, 1h, 3h, ... 

var t = parseInt(delay.match(/\d+/)[0], 10), 
        unit = "", 
        d = 0; 
switch(delay.match(/[ms]/i)[0]) { 
        case "s": 
                unit = "secondes"; 
                d = t * 1000; 
                break; 
        case "m": 
                unit = "minutes"; 
                d = t * 60000; 
                break; 
        case "h": 
                unit = "heures"; 
                d = t * 3600000; 
                break; 
} 

setInterval("window.location.reload()", d); 

alert("Vous n'aviez pas activé la page depuis " + t + " " + unit);

when i want show the var "extern", the pop-up give my "extern" and not the value of the DIV...

Please could you help me ?

Ps : The second part of my code work properly, it's a refresh of the web page

I'm trying to make a Tampermonkey script to unhide one DIV defined like that

<div id="div2" style="display: none;"> 

My script doesn't work and I don't know why...

// ==UserScript== 
// @name            Actualisation Vérification Infra 
// @namespace       http://use.i.E.your.homepage/ 
// @version         0.1 
// @description     Permet de recharger la page toutes les x millisecondes afin de garder la session active 
// @match           https://reportingogd.truc.fr/reporting/afficherSynthese.do* 
// @copyright       2013+, The PCU Team 
// ==/UserScript== 

var extern = document.getElementById('div2').style.display; 
alert('extern'); 

// Refresh toutes les xx minutes  
var delay = "30m"; // Remplacer par le temps souhaité, 1s, 10s, 60s, 1m, 15m, 30m, 1h, 3h, ... 

var t = parseInt(delay.match(/\d+/)[0], 10), 
        unit = "", 
        d = 0; 
switch(delay.match(/[ms]/i)[0]) { 
        case "s": 
                unit = "secondes"; 
                d = t * 1000; 
                break; 
        case "m": 
                unit = "minutes"; 
                d = t * 60000; 
                break; 
        case "h": 
                unit = "heures"; 
                d = t * 3600000; 
                break; 
} 

setInterval("window.location.reload()", d); 

alert("Vous n'aviez pas activé la page depuis " + t + " " + unit);

when i want show the var "extern", the pop-up give my "extern" and not the value of the DIV...

Please could you help me ?

Ps : The second part of my code work properly, it's a refresh of the web page

Share Improve this question edited Jul 19, 2013 at 11:30 Brock Adams 93.7k23 gold badges241 silver badges305 bronze badges asked Jul 19, 2013 at 11:09 user2599181user2599181 91 silver badge2 bronze badges 1
  • 1 Take out the quotes around extern in the alert. alert(extern) else it alerts a string – dievardump Commented Jul 19, 2013 at 11:19
Add a ment  | 

1 Answer 1

Reset to default 4

Your alert alerts 'extern' because you alert it as a string.

alert(extern) will alert the good value.

And to make the div visible, just:

document.getElementById('div2').style.display = 'block';

Post a comment

comment list (0)

  1. No comments so far