最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jQuery: Javascript throws Error "The operation is insecure" when setting value - Stack Overflow

programmeradmin6浏览0评论

I am trying to find a fallback solution for browsers who do not interpret the placeholder attribute for input elements. I have this simple jQuery Script but it throws an Error

SecurityError: "The operation is insecure.
this.value = val;"

Here's my script:

$('document').ready(function(){
       $('input').each(function() {
           if ($(this).val() === '' || $(this).val() === undefined) {
               $(this).val($(this).attr('placeholder'));
           }
       });
});

Anyone any ideas what i can do? Or what i am doing wrong? Or what this error means? It happens in Firefox, haven't tested it in other Browsers yet.

I am trying to find a fallback solution for browsers who do not interpret the placeholder attribute for input elements. I have this simple jQuery Script but it throws an Error

SecurityError: "The operation is insecure.
this.value = val;"

Here's my script:

$('document').ready(function(){
       $('input').each(function() {
           if ($(this).val() === '' || $(this).val() === undefined) {
               $(this).val($(this).attr('placeholder'));
           }
       });
});

Anyone any ideas what i can do? Or what i am doing wrong? Or what this error means? It happens in Firefox, haven't tested it in other Browsers yet.

Share Improve this question asked Aug 2, 2012 at 15:33 Andresch SerjAndresch Serj 37.4k16 gold badges61 silver badges104 bronze badges 4
  • 2 FWIW $(this).val() will never return undefined. – Felix Kling Commented Aug 2, 2012 at 15:35
  • 1 Do you have any browser extensions or plugins running that could be disabling Javascript from modifying form values? – chrisfrancis27 Commented Aug 2, 2012 at 15:37
  • Do you have password inputs on your page? Could you break the script down to a specific <input> element? – Bergi Commented Aug 2, 2012 at 15:55
  • On a particular browser at some user location, I get this error when I try to save a text in browser's local storage. Must be some browser security setting. – Allen King Commented Feb 1, 2015 at 19:43
Add a ment  | 

2 Answers 2

Reset to default 28

I have just fixed a similar problem in my project. It turned out that I was trying to set a value of a <input type="file" ...> input. It seems that you may be facing the same problem, because you are selecting all inputs of a document regardless of their type.

If you have firebug installed, try looking for the input that causes this error by inserting a log mand before trying to modify the input's value.

$('document').ready(function(){
       $('input').each(function() {
           if ($(this).val() === '' || $(this).val() === undefined) {

               // Log goes here
               window.console.log(
                   'There is an input without a value!', 
                   this);

               $(this).val($(this).attr('placeholder'));
           }
       });
});

I had an insecure warning in conjunction with antoher function. The reason there simply was, that a library function was called with an array given as parameter, but it expected an element (dom). The result was the expected, but I'm sure, this won't be in any case. So check if the types of your variables are the one you (or the other side) want's it to.

发布评论

评论列表(0)

  1. 暂无评论