TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

jQuery Lock Plugin – prevent some users from changing content in your page

29 pointsby kauegimenesabout 9 years ago

20 comments

pakabout 9 years ago
Welcome to the rebirth of the &quot;right-click blocking&quot; scripts. Please, take a trip with me down memory lane, to the glorious days of DHTML in 1998, when there were serious attempts to use JavaScript to &quot;prevent people from stealing your images and code!&quot; <a href="http:&#x2F;&#x2F;www.java-scripts.net&#x2F;javascripts&#x2F;No-Right-Click.phtml" rel="nofollow">http:&#x2F;&#x2F;www.java-scripts.net&#x2F;javascripts&#x2F;No-Right-Click.phtml</a><p>What is old is new, what is new is old.
评论 #11506106 未加载
评论 #11506509 未加载
devin_laneabout 9 years ago
You can remove the DOMSubtreeModified event listener first, then you are free to modify &quot;locked&quot; content as desired. I hope to not see a day where the Web Inspector lacks proper facilities to inspect and modify a page.
评论 #11505896 未加载
评论 #11505777 未加载
steegoabout 9 years ago
Visited the page and ran this in the console:<p><pre><code> $(&quot;code.locked&quot;).after($(&quot;&lt;code class=\&quot;locked\&quot;&gt;I circumvent you!&lt;&#x2F;code&gt;&quot;)).remove() </code></pre> Clearly this doesn&#x27;t prevent scripts from changing it, nor does it prevent users from deleting the locked elements and replacing it with something else.<p>What&#x27;s the point of this cat and mouse game?
评论 #11506729 未加载
bobp127001about 9 years ago
It&#x27;s cool, but I guess I don&#x27;t see the point because I&#x27;m not sure how big the intersection is between users that can use Chrome developer tools, and those who can&#x27;t disable this [0].<p>[0]: <a href="http:&#x2F;&#x2F;i.imgur.com&#x2F;jvExNWT.png" rel="nofollow">http:&#x2F;&#x2F;i.imgur.com&#x2F;jvExNWT.png</a>
评论 #11505856 未加载
评论 #11505804 未加载
jtokophabout 9 years ago
Most of the comments here are bashing this for ease of defeat and not having a useful reason for it&#x27;s existence.<p>While I agree that it&#x27;s easy to defeat, it could be interesting in test cases to make sure there aren&#x27;t any DOM side effects to an operation. You could also use it to ensure that there are proper side effects. Probably not the best way to do it, but still a cool idea in my opinion.
kevincennisabout 9 years ago
For those wondering, you can get around this globally by listening during the capture phase and stopping propagation.<p><pre><code> document.addEventListener(&#x27;DOMSubtreeModified&#x27;, function( e ) { e.stopPropagation(); }, true );</code></pre>
评论 #11506674 未加载
footaabout 9 years ago
So we can safely assume anything these people build doesn&#x27;t validate their inputs server side?
评论 #11506507 未加载
CM30about 9 years ago
So it&#x27;s like those old scripts to stop right clicking&#x2F;content selecting&#x2F;other stuff then?<p>The ones that were (and still are) completely useless because the scripts are client side and trivially easy to &#x27;bypass&#x27;? Yeah, I think I&#x27;ll pass.<p>Funny enough, uBlock Origin doesn&#x27;t seem to like this very much, since I just waltzed in and edited the &#x27;protected&#x27; elements without so much as an alert:<p><a href="https:&#x2F;&#x2F;dl.dropboxusercontent.com&#x2F;u&#x2F;67216205&#x2F;jqueryunlocked.png" rel="nofollow">https:&#x2F;&#x2F;dl.dropboxusercontent.com&#x2F;u&#x2F;67216205&#x2F;jqueryunlocked....</a><p>What&#x27;s next, a jQuery marquee plugin? Or maybe jQuery blinking text...
deckar01about 9 years ago
It might be more useful to silently report modifications to sensitive elements.<p>I could only really see this being useful for malicious browser plugins that aren&#x27;t targeted at the specific site.
acbabisabout 9 years ago
The `.lock` function takes two optional parameters: `alertMessage` and `customHandler`. `customHandler` is a callback invoked when a content change is attempted. `alertMessage` is a convenience function that calls `alert`; it could be trivially implemented by the client programmer using `customHandler`. The author is ostensibly suggesting that `alert` is a common use case. I think he&#x27;s trolling us.<p>EDIT: Just saw that the author is a company. There goes my theory.
Sean1708about 9 years ago
Does this not work on Firefox? I expected to not be able to change anything about the two &quot;locked&quot; elements, but I seem to be able to change the text, class, or even delete them with no issue.<p>Edit: Interestingly if I click &quot;Edit as HTML&quot; I can change them to my heart&#x27;s content, but if I try just double clicking the text it won&#x27;t let me make changes.
matthugginsabout 9 years ago
But why?
评论 #11505751 未加载
评论 #11506228 未加载
评论 #11505739 未加载
throwanemabout 9 years ago
&quot;The idea of the plugin is to prevent users without technical background from changing the page HTML. For example. many eCommerce customers change the price of the product using dev tools and send a screenshoot.&quot;<p>Yeah, good luck with that.
Zekioabout 9 years ago
well, didn&#x27;t lock anything for me... uMatrix didn&#x27;t allow it to run the JS
psheetsabout 9 years ago
I feel like this is a band aid for core design flaws.
kauegimenesabout 9 years ago
The idea of the plugin is to prevent users with no technical background from changing the page HTML. For example. many eCommerce customers change the price of the product using dev tools and send a screenshoot trying to get free discounts.
评论 #11510445 未加载
constoabout 9 years ago
Just blacklist the site from running javascript. Problem solved.
spenvoabout 9 years ago
bug : after locking &#x27;body&#x27; - i tried appending an element to a p tag and hit an infinite loop&#x2F;maximum call stack exceeded error
prophesiabout 9 years ago
Sure, it won&#x27;t actually stop people from changing content. But I can see myself leaving some fun easter eggs with this.
评论 #11506536 未加载
venomsnakeabout 9 years ago
some users = the ones that cannot find F12