Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Anyone want to guess what this does in javascript?

Anyone want to guess what this does in javascript?

Scheduled Pinned Locked Moved The Lounge
javascripttutorialquestion
20 Posts 12 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Daniel Scott

    Seems to me that it's just going to alert "hello!" once and that's it, but this is probably some kind of trick-question..

    M Offline
    M Offline
    M dHatter
    wrote on last edited by
    #10

    It's a rhetorical question dan. :laugh:

    "I do not know with what weapons World War 3 will be fought, but World War 4 will be fought with sticks and stones." Einstein "Few things are harder to put up with than the annoyance of a good example." Mark Twain

    1 Reply Last reply
    0
    • L Luc Pattyn

      Thank you very much. We now need an article and some techniques to protect against JavaScript Injection Attacks. :)

      Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

      M Offline
      M Offline
      M dHatter
      wrote on last edited by
      #11

      If i had the time, you can write it and use my code example.

      "I do not know with what weapons World War 3 will be fought, but World War 4 will be fought with sticks and stones." Einstein "Few things are harder to put up with than the annoyance of a good example." Mark Twain

      L 1 Reply Last reply
      0
      • M M dHatter

        If i had the time, you can write it and use my code example.

        "I do not know with what weapons World War 3 will be fought, but World War 4 will be fought with sticks and stones." Einstein "Few things are harder to put up with than the annoyance of a good example." Mark Twain

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #12

        I don't think I know enough about the subject to warrant an article. :)

        Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

        M 2 Replies Last reply
        0
        • L Luc Pattyn

          I don't think I know enough about the subject to warrant an article. :)

          Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

          M Offline
          M Offline
          M dHatter
          wrote on last edited by
          #13

          Me neither, we should get john to do it

          "I do not know with what weapons World War 3 will be fought, but World War 4 will be fought with sticks and stones." Einstein "Few things are harder to put up with than the annoyance of a good example." Mark Twain

          1 Reply Last reply
          0
          • L Luc Pattyn

            I don't think I know enough about the subject to warrant an article. :)

            Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

            Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

            M Offline
            M Offline
            M dHatter
            wrote on last edited by
            #14

            Here I just made a tip or trick out of it. http://www.codeproject.com/Tips/196535/Javascript-Injection-at-its-Finest-without-even-us.aspx[^]

            "I do not know with what weapons World War 3 will be fought, but World War 4 will be fought with sticks and stones." Einstein "Few things are harder to put up with than the annoyance of a good example." Mark Twain

            1 Reply Last reply
            0
            • M M dHatter

              String.prototype.code = function(){ return (new Function('with(this) { return ' + this + '}' )).call({}); };

              var s = 'alert("hello!");'

              s.code();

              "I do not know with what weapons World War 3 will be fought, but World War 4 will be fought with sticks and stones." Einstein "Few things are harder to put up with than the annoyance of a good example." Mark Twain

              modified on Sunday, May 15, 2011 12:54 PM

              A Offline
              A Offline
              Andy Brummer
              wrote on last edited by
              #15

              I don't know why you needed to modify the string prototype, but Function and eval both allow you to dynamically execute javascript. You can also just type it directly into the address bar, use a bookmarklet or a debug console.

              Curvature of the Mind now with 3D

              1 Reply Last reply
              0
              • M M dHatter

                String.prototype.code = function(){ return (new Function('with(this) { return ' + this + '}' )).call({}); };

                var s = 'alert("hello!");'

                s.code();

                "I do not know with what weapons World War 3 will be fought, but World War 4 will be fought with sticks and stones." Einstein "Few things are harder to put up with than the annoyance of a good example." Mark Twain

                modified on Sunday, May 15, 2011 12:54 PM

                B Offline
                B Offline
                BillWoodruff
                wrote on last edited by
                #16

                Hi VectorX, That code fragment just tells me that JavaScript, like LISP, and PostScript, happens to be a programming language in which the distinction between groups of characters and executable code is trivial to blur. best, Bill

                "Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844

                1 Reply Last reply
                0
                • M M dHatter

                  String.prototype.code = function(){ return (new Function('with(this) { return ' + this + '}' )).call({}); };

                  var s = 'alert("hello!");'

                  s.code();

                  "I do not know with what weapons World War 3 will be fought, but World War 4 will be fought with sticks and stones." Einstein "Few things are harder to put up with than the annoyance of a good example." Mark Twain

                  modified on Sunday, May 15, 2011 12:54 PM

                  V Offline
                  V Offline
                  Vic Rauch
                  wrote on last edited by
                  #17

                  And now, to the unexpecting, there are people on facebook asking others on facebook to copy something and paste that into the address bar. It then sends itself to all of the user's facebook friends. Very insidious!

                  1 Reply Last reply
                  0
                  • M M dHatter

                    String.prototype.code = function(){ return (new Function('with(this) { return ' + this + '}' )).call({}); };

                    var s = 'alert("hello!");'

                    s.code();

                    "I do not know with what weapons World War 3 will be fought, but World War 4 will be fought with sticks and stones." Einstein "Few things are harder to put up with than the annoyance of a good example." Mark Twain

                    modified on Sunday, May 15, 2011 12:54 PM

                    D Offline
                    D Offline
                    dpminusa
                    wrote on last edited by
                    #18

                    I wonder what this lisp is all about. Hmmm... void(0).

                    "Courtesy is the product of a mature, disciplined mind ... ridicule is lack of the same - DPM"

                    1 Reply Last reply
                    0
                    • L Luc Pattyn

                      Thank you very much. We now need an article and some techniques to protect against JavaScript Injection Attacks. :)

                      Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

                      Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

                      A Offline
                      A Offline
                      Adar Wesley
                      wrote on last edited by
                      #19

                      There is absolutly no need to protect against Javascript injection. Just asume it is not safe. It runs on the "attackers" machine in his/her browser. They can mess with anything they want anyway. Your application defenses should be on the server side anyway. On the other hand, using Javascript's ability to dynamically eval code from string can be extremely powerfull. --- Adar Wesley

                      L 1 Reply Last reply
                      0
                      • A Adar Wesley

                        There is absolutly no need to protect against Javascript injection. Just asume it is not safe. It runs on the "attackers" machine in his/her browser. They can mess with anything they want anyway. Your application defenses should be on the server side anyway. On the other hand, using Javascript's ability to dynamically eval code from string can be extremely powerfull. --- Adar Wesley

                        L Offline
                        L Offline
                        Luc Pattyn
                        wrote on last edited by
                        #20

                        I can see your point.

                        Adar Wesley wrote:

                        Your application defenses should be on the server side anyway.

                        Absolutely, the main defenses are the ones on the server, I agree. :)

                        Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

                        Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups