For some unfathomable reason I can reliably detect double spaces in text input elements on localhost but not on live sites with everything verified (deleted/upload files, browsing with cache disabled, manually verifying the script file is updated, testing in the console, etc).
My original code:
if (document.getElementById('example').value.indexOf(' ')!='-1') {}
My second attempt:
if (document.getElementById('example').value.split(' ').length>1)
I'm completely baffled, the script works fine in Firefox and Chrome locally though not live and I am absolutely 100% certain that everything on the server has been updated. I've even run the validation with the script commented out just to make certain.
Got it! So I don't know what the heck was wrong with the other code...it worked fine on localhost and I'm at a complete loss about that issue however I did some more poking around and determined that I can detect double spaces in JavaScript using the following:
if (document.getElementById('example').value.match(/\s{2,}/)!=null)
Related
I'm trying to use this simple code:
javascript:document.getElementsByName("tabla-usuarios_length")[0].options[3].text="10000";
I tested it on Chrome(URL) and it works perfectly, also in both Firefox and Google Chrome's Console.
In both console's it works and it gives me like a message "10000" in the console.
In Firefox URL, it redirects like to a blank page with that same message instead of just working on the page I am. so since it goes to that blank page I can't see the results and to come back to the page I was I have to tap on back and of course it reloads losing the possible change that I made with the JS code..
I really need it working with the url stuff since I need to use it with iMacros (URL GOTO=javascript:....) so I can't use it with Console.
Thanks I hope I explained myself correctly.
Three alternatives
wrap a simple command in void()
javascript:void(document.getElementsByName("tabla-usuarios_length")[0].options[3].text="10000");
or - use IIFE
javascript:(function() {document.getElementsByName("tabla-usuarios_length")[0].options[3].text="10000";})();
or, again only with simple command, use , operator like so:
javascript:document.getElementsByName("tabla-usuarios_length")[0].options[3].text="10000",undefined;
Seems Firefox looks at the return value of bookmarklets. If it is udefined it works as expected
All complex bookmarklets I've ever seen were always wrapped in IIFE - which is why they've always worked
Even the wikipedia page (which I only now read) shows this requirement - with one other format for them
javascript:{arbitrary script};void(0);
I am editing an existing site, which is a typical merchant site. A series of PHP files with one main index that loads in the various content pages.
The main index.php, using <script>, loads in jsFunctions.js.
When ever I modify the jsFunctions.js file, the index only loads the jsFunctions.js partially. For example I will get a firebug error such as 'unterminated string literal' or 'missing end }' or similar. The errors themselves make sense, because the js file isn't fully loading, a brace or quote is missing and throwing an error. It is seemingly random, sometimes it will load 100 lines of the js, then sometimes 105 lines, etc.
But why would the file be partially loading if i edit it? If i remove the single line of my code, no matter how simple, it starts working again?
Any ideas?
Are you editing a file with inconsistent line-endings, which editor? Issues like line-ending or weird unicode characters cause the issues like you've described.
I would take the contents of the file after your edit do a copy/paste exact as it is to JSLint: http://www.jslint.com/
JSLint is a validation tool for your script, before checking for best practices though, it'll check that your script is valid at all. See if you get the same error, it could be a weird character that's slipped in there causing issues, JSLint will alert you to this and where it's at.
Apparently it was some kind of server serving issue. If I refreshed a random amount of times, the full js would load. Once loaded it works 100% after that, well until I uploaded a new copy, then I would have to refresh a couple of times (or possibly wait 1-2 mins).
Filezilla was showing that the upload was complete, but the server simply didn't seem ready to output it.
Thanks guys
On the server lies a html file with javascript code included.
This javascript code includes a method called something like "CheckObject".
This file works for all users, except one specific (but important).
He gets a javascript error and in his browser sourcode appears something unbelievable:
The methodname "CheckObject" is replaced with "Check!==ect", means the "Obj" of the method name is replaced with !==.
Why could that be?
Hope anybody can help me!
Best regards
If he's using a browser that supports extensions (like Firefox, Chrome, and some others), it's probably worth disabling all of the extensions and seeing if the problem goes away.
If you haven't already, I'd completely clear his cache in case there was a bad page transfer once and the browser is reusing it.
I can't imagine how it would be happening reliably otherwise.
We recently started using SVN Keywords to automatically append the current revision number to all our <script src="..."> includes (so it looks like this: <script language="javascript" src="some/javascript.js?v=$Revision: 1234 $"> </script>). This way each time we push a new copy of the code to production, user caches won't cause users to still be using old script revisions.
It works great, except for IE6. For some reason, IE6 sporadically acts as though some of those files didn't exist. We may get weird error statements like "Unterminated String Literal on line 1234," but if you try to attach a debugger process to it, it won't halt on this line (if you say "Yes" to the debugger prompt, nothing happens, and page execution continues). A log entry for it shows up in IIS logs, indicating the user is definitely receiving the file (status code 200, with the appropriate amount of bytes transferred).
It also only seems to happen when the pages are served over https, not over standard http. To further compound things, it doesn't necessarily happen all the time; you might refresh a page 5 times and everything works, then you might refresh it 20 more times and it fails every time. For most users it seems to always work or else to always fail. It is even unpredictable when you have multiple users in a corporate environment whose security and cache settings are forcibly identical.
Any thoughts or suggestions would be greatly appreciated, this has been driving me crazy for weeks.
Check your log with fiddler2 to make sure the browser request the page, and do not use the cache instead. Also check the URL of the JS script and the header returned.
Are you using GZip? There has been issues reported with it.
I would suggest testing using Internet Explorer Application Compatibility VPC Image. That way, you can do your tests with a 100% IE6, and not one of those plugin that claims to simulate IE6 inside another browser.
I think this is a very clever idea. However, I think the issue could be related to the spaces in the url. Technically, the url should have the spaces encoded.
See if you can customize the keywords in SVN to generate a revision number without special characters.
Thus far this is what I've tried, I'm using Firefox 3.07
Make sure in about:config that the property browser.cache.check_doc_frequency is set to 1 which the browser interprets as "check for a new page every time".
Make sure in about:config that the property security.fileuri.strict_origin_policy is set to false.
When opening your browser be sure to specify to the testrunner.html page which test you want to run using the testpage parameter,I.E.: file:///.../testRunner.html?testpage=c:/temp/someTest.html
Tak an additional random parameter on the end to ensure that the cache is gone.
Everything above seems to work, except it is still caching my *.js files for some stupid reason. I really thought it would have had to do with changing the random parameter at the end to kill the cache, but that doesn't seem to be doing the trick. What else can be done to make JSUnit work with Firefox 3.07? The files are located on my hdd.
Have you tried CTRL + SHIFT + R to refresh without using cache?
No, that doesn't work. The problem is that it is caching the *.js files. When you do CTRL + SHIFT + R it is only refreshing the test runner page.
Thus far this is what I've tried, I'm using Firefox 3.07
1.
Make sure in about:config that the property browser.cache.check_doc_frequency is set to 1 which the browser interprets as "check for a new page every time".
2.
Make sure in about:config that the property security.fileuri.strict_origin_policy is set to false.
3.
When opening your browser be sure to specify to the testrunner.html page which test you want to run using the testpage parameter,
I.E.: file:///.../testRunner.html?testpage=c:/temp/someTest.html
4.
Tak an additional random parameter on the end to ensure that the cache is gone.
Everything above seems to work, except it is still caching my *.js files for some stupid reason. I really thought it would have had to do with changing the random parameter at the end to kill the cache, but that doesn't seem to be doing the trick. What else can be done to make JSUnit work with Firefox 3.07? The files are located on my hdd.
Try editing the network.http.use-cache property in about:config.
e.g., network.http.use-cache = false
Was pulling my hair out with same problem.
This finally worked for me:
Firefox Menu: Tools/Web Developer/Disable/Disable Cache