Create Boot using document.createElement ()

1

I really need some help, thanks. I need to create this function:

<input type="button" value="Refresh Page" onClick="history.go(0)">

But it must be created using the document.createElement () method and I'm not getting it, I've already tried it in several ways but I always end up with an empty input text box that does not work, and the button does not even appear. If it is not possible to create this button, a writable AGAIN text for refresh also works. I tried to do this and the page is in eternal reload before being loaded. Taking advantage of the question, if I change the history.go(0) to history.go(-1) does it return to the previous page? Thank you in advance. For link

var ae = document.createElement('a');
var eText = document.createTextNode("AGAIN");
ae.appendChild(eText);
ae.title = "AGAIN";
ae.href = window.location.reload();
document.body.appendChild(ae);

For Botao

    var batsu = document.createElement("input");  
    batsu.setAttribute('type', 'button');  
    batsu.setAttribute('valeu', 'AGAIN');  
    batsu.setAttribute('onClick', 'history.go(0)');  
    document.body.appendChild(batsu);
    
asked by anonymous 03.07.2017 / 22:21

1 answer

0

To create a button with document.createElement , follow the example:

Button

function createButton()
{
     var btn = document.createElement('BUTTON');
     var lbl = document.createTextNode("CLICK ME");        
     btn.appendChild(lbl);   
     btn.onclick = function()
     {
        window.history.go(0);
     }
     document.body.appendChild(btn);    
}

createButton();

input type button

var batsu = document.createElement("input");  
    batsu.type = 'button';  
    batsu.value = 'AGAIN';  
    batsu.onclick = function() { window.history.go(0); };  
    document.body.appendChild(batsu);

References

03.07.2017 / 22:37