Help sought for browser button

  • Thread starter mailto.anand.hariharan
  • Start date
M

mailto.anand.hariharan

Hello group.

This is my first message in this group, and my first stab at
Javascript.

I am trying to tweak the code for the "FOLDOC button"
(http://foldoc.org/foldoc/tools.html) to be able to execute a DB query
over my firm's intra-net.

The source code for the IE button is as follows:

javascript:f=document.frames.length;q=(f?'':document.selection.createRange().text);for(i=0;i<document.frames.length;i++){q=document.frames.document.selection.createRange().text;if(q!='')break;}if(q=='')void(q=prompt('search
foldoc:',''));if(q!=null){q='http://www.foldoc.org/?'+escape(q);void(f?open(q):window.location=q)}

which when reasonably indented looks like this:

javascript:
f=document.frames.length;
q=(f?'':document.selection.createRange().text);
for(i=0; i<document.frames.length; i++)
{
q=document.frames.document.selection.createRange().text;
if(q!='')
break;
}
if(q=='')
void(q=prompt('search foldoc:',''));
if(q!=null)
{
q='http://www.foldoc.org/?'+escape(q);
void(f?open(q):window.location=q)
}

For reasons I don't understand, IE *requires* that the entire code be
in one single line. Notwithstanding that, the FOLDOC button works
quite well.

My tweak to the FOLDOC code attempts to do this:
* In either the selected text, or the text entered in the 'Prompt'
box,
* Strip off all text EXCEPT,
* numbers of 5 or more digits.

For example, when a text such as

In v6.1.25.4 release, defects 12345, 23456, 78901 and 24211 were fixed
on 4/5/6. Docs are available at ftp://12.34.56.78/TR34251.txt

is selected (or copy-pasted), the string should be reduced to

12345,23456,78901,24211,34251

before appending it to my query URL.

My attempt is as follows (I have laid it out indented and spread out
although the IE button code has it all in one single line):

f=document.frames.length;
q=(f?'':document.selection.createRange().text);
for(i=0; i<f; i++)
{
q=document.frames.document.selection.createRange().text;
if(q!='')
break;
}
if(q=='')
void(q=prompt('Search for Defect ID:',''));
if(q!='' && q!=null)
{
q=q.replace(/\D+/g,'#');
q=q.replace(/\b\d{1,4}#/g,'#');
q=q.replace(/#+/g,',');
q=q.replace(/(^\,|\,$)/gm,'');
q='http://intranet.myfirm.com/query.asp?JTSNo='+escape(q);
}
else
q='http://intranet.myfirm.com';
void(f?open(q):window.location=q);

The problem is, when I click the button (for this code), NOTHING
happens.

Some observations:
* I use IE 6.0.2900 on XP SP2 (includes all current patches/security
fixes).
* I have UNCHECKED the "Disable script debugging" option as well as
CHECKED the "Display notification on every script error".
* I've tried installing Microsoft script debugger.
* The above code reduced to a single line is well within the 2083
character limit.

None of them have any effect, i.e., IE does not seem to think there is
any error. It simply just does not do anything.

The help I seek:
* Is there anything wrong with the code above? Is there any better way
to do what I have sought to do?
* Can anyone explain why nothing happens, yet another button with near
identical code works flawlessly?
* In general, how do I debug such code?

All advice/insights appreciated,
- Anand Hariharan
 
V

VK

For reasons I don't understand, IE *requires* that the entire code be
in one single line. Notwithstanding that, the FOLDOC button works
quite well.

javascript: pseudo-protocol is still *protocol* so should follow the
URL schema where line breaks are not allowed unless escaped.
q='http://intranet.myfirm.com/query.asp?JTSNo='+escape(q);
}
else
q='http://intranet.myfirm.com';
void(f?open(q):window.location=q);

The problem is, when I click the button (for this code), NOTHING
happens.

Some observations:
* I use IE 6.0.2900 on XP SP2 (includes all current patches/security
fixes).
* I have UNCHECKED the "Disable script debugging" option as well as
CHECKED the "Display notification on every script error".
* I've tried installing Microsoft script debugger.
* The above code reduced to a single line is well within the 2083
character limit.

None of them have any effect, i.e., IE does not seem to think there is
any error. It simply just does not do anything.

The help I seek:
* Is there anything wrong with the code above? Is there any better way
to do what I have sought to do?
* Can anyone explain why nothing happens, yet another button with near
identical code works flawlessly?
* In general, how do I debug such code?

Create a test page and place your code as a normal JavaScript function
(so line breaks between statements are OK). Call this function on
button click. Place alert() in different places (starting from the
function first line) to see where the execution breaks or even if it
starts at all.
 
M

mailto.anand.hariharan

VK said:
javascript: pseudo-protocol is still *protocol* so should follow the
URL schema where line breaks are not allowed unless escaped.

Thanks for the response, VK.

If by 'escaping' you mean ending each line with a back-slash, tried
that and that does not work (IE reports invalid character).
Create a test page and place your code as a normal JavaScript function
(so line breaks between statements are OK). Call this function on
button click. Place alert() in different places (starting from the
function first line) to see where the execution breaks or even if it
starts at all.

Like I said, I am new with Javascript, and I admit I do not know how to
"".

I did put alert at a number of places (even at the first line) - as I
said NOTHING happens (i.e., nothing gets executed ever).

However, when I removed the 'replace' calls, it works and has the
semantics of the FOLDOC button (i.e., whatever text entered or selected
is appended to the query). So, the code that I put in for
pre-processing the input seemingly causes some parse problems for IE?

NB: The code, the intention behind my pre-processing is all in my
original post. I can reproduce them again if you'd like.

best wishes,
- Anand
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,265
Latest member
TodLarocca

Latest Threads

Top