Provided is an anti-theft guardrail connecting piece with a tension spring and an electronic switch. The anti-theft guardrail connecting piece with the tension spring and the electronic switch comprises a connecting piece body, the tension spring and the electronic switch, wherein the connecting piece body comprises a rectangular base plate, a hinge is arranged at the front end of the base plate, a side plate is upwards arranged on the portion, in the middle of the base plate, of the base plate, a front plate is arranged on the upper portion of the side plate, installing holes are further formed in the base plate, a switch box is arranged on the front plate, the electronic switch and the tension spring are arranged in the switch box, the hinge is fixed to a guardrail bottom frame, and the tension spring is fixed to a guardrail frame. The anti-theft guardrail connecting piece is installed on the portions, on the left side and the right side of a window, of a sill, a guardrail is parallel to the window, when a guardrail bears external force applied by thieves in the process of climbing operation or pushing and pulling operation or tread operation or the like, the guardrail rotates by a certain angle, the electronic switch is turned on, an alarm signal is sent, an alarm host connected with the electronic switch sends alarm information, the Internet of things can be further formed through a communication network, and remote control is achieved.