Why won't code work without void(0);

Discussion in 'JavaScript' started by cc2365, Jun 8, 2009.

  1. #1
    Sometimes I visit websites with colorful background, which makes words over it hard to read. So I type the following code in the address bar to solve this problem:
    javascript:document.body.style.background='none';
    HTML:
    But I doesn't work. Therefore I change the code above to:
    javascript:document.body.style.background='none';void(0);
    HTML:
    And now it works. But I don't understand:
    1. What's the code void(0); for;
    2. Why won't this code work without void(0);.
    Any explanation will be appreciated. :)
     
    cc2365, Jun 8, 2009 IP
  2. Worldwidirectory

    Worldwidirectory Peon

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    So the script returns nothing, otherwise you'll lose the current page. You can also include the code into the void:

    javascript:void(document.body.style.background='none')
     
    Worldwidirectory, Jun 8, 2009 IP