simulate form submit (why does it reload the page?)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • best123456
    New Member
    • Jul 2018
    • 1

    simulate form submit (why does it reload the page?)

    In short:

    Execute this js script on https://skribbl.io (via your browser console)

    Problem: it "switches"/reloads the page after successfully joining

    Code:
    this.Enterrr = document.getElementById('formLogin');
    
    let ev = document.createEvent('Event');
    
    ev.initEvent('submit');
    
    this.Enterrr.dispatchEvent(ev);
    Who can change the code so the switching/reloading does not appear?


    Even easier code:
    Code:
    var foo = document.getElementById('formLogin');
    foo.dispatchEvent(new Event('submit'));
    Also reloads the page... And simply clicking manually or pressing enter does not lead to a page reload. Weird...
    Last edited by best123456; Jul 3 '18, 03:12 PM. Reason: better
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5388

    #2
    well - the question is more - what are you trying to achieve. to prevent the default submit behaviour you can use:

    event.preventDe fault()

    but in this case the form wont be submitted - thus making it obsolet to even fire a submit-event. so as i said - some more information and may be posting the html-form would be helpful for a useful answer. if the form has a real submit button it will reload - its easy to see in chrome's dev-tools - so i doubt that the submit from the submit button behaves different from the programmatic submit. this can only happen if there is other code that might cause this or its not a real submit button.

    Comment

    Working...