Link to home
Start Free TrialLog in
Avatar of PaulCaswell
PaulCaswellFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Execute JScript in FireFox

All,

I have a JScript tool I use in Explorer on web pages. I can drag the tool from my favorites onto the page and it is performed on the page contents.

How can I do the equivalen in FireFox?

Paul
SOLUTION
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PaulCaswell

ASKER

>>You mean a bookmarklet?
So it is possible!

I have a tool in C:\Tools\MyTool.js. What do I change my bookmarklet (how cute) to so it executes instead of opening?

Paul
ahhh...  now it gets tricky...

I never found a way of doing this :-(

I only managed to execute commands less than 1000 chars (or something) in length, due to restrictions in URL length (under IE)

It *may* be possible to add a link to your script into the page, then execute commands from the script, but I would imagine you'd hit all sorts of cross-site scripting security issues...

What is it you're trying to do?  Maybe something already exists to do it?

Tim
Its actually a points splitter I found. It was written by DanRollins. Essentially, you hit the 'Split Points' link on your question and then invoke the script. It walks through the question building a list of all contributors and distributes the points equally among them. I doubt if thats possible in one line.

Obviously there's no chance of embedding it in the page.

I used to use Explorer but since I've moved over to FireFox I'm not going back :-) In explorer you just drop the script on the page and it executes.

Paul
I am not familliar with JavaScript but something like:

javascript:function d(){ execute( "C:\Tools\MyTool.js" );};d();

would be the sort of thing I suspect I am looking for.

Paul
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Looks like progress!

It doesnt work for me! I've traced it back to extracting the inner HTML. If I do 's=document.body.innerHTML;alert(s.length);' I get zero. Any ideas?

The code looks like:
"javascript:function splt(){s=document.body.innerHTML;alert(s.length)..."

Paul
This gives '0':

javascript:function splt(){var s=document.body.innerHTML;alert(s.length);}splt();

What am I doing wrong?

Paul
Strange...  it gives me a number... :-/

I'm on Firefox 1.5
>>I'm on Firefox 1.5
1.5.0.1!

Oddly though, after it executes, my Bookmarks sidebar goes blank! Could I have an extension that's interfering?

Happens on other sites too!

Paul
Works on mine :-/
Avatar of ndixon
ndixon

this is a little out of your topic area, but...

JScript has descrete differences to Javascript JScript - JScript is microsoft's own take on the scripting language, and although for the most part it is compatable in other browsers, it contains features that are only available in IE.
All,

I disabled all my extensions (wierd feeling) and tried it again:

javascript:function splt(){s=document.body.innerHTML;alert(s.length);}splt();

Still showing '0'. Any more thoughts?

Is there any other way of getting the contents of the current page?

I keep feeling that the disappearance of the bookmarks sidebar after execution is important. What might that mean?

Paul
>> I keep feeling that the disappearance of the bookmarks sidebar after execution is important. What might that mean?

It's odd, because mine doesn't disappear :-/
A technique I often use to track down bugs is to try to discover how I would do it deliberately so:

How would you make the sidebar go blank (if its there) and both appear AND be blank if its not there, using JScript?

Paul

P.S. Could this be a FF Version issue? As I said, I have 1.5.0.1. Is that the same as yours? Are you running Windows XP-SP2 like me?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Wow! I didnt spot that! Good catch! That explains the whole thing! Even the blanking of the sidebar!

My fragment now gives me 61481 for this page so I should be able to resurrect the original and test it.

I think I'll split the points here :-)

Paul
yay!  yeah, now the code mplungjan gave here http:Q_21807403.html#16413034 should work fine :-)

i dont use the sidebar...  that's my excuse anyway ;-)

good luck!

Tim
It worked! Thanks all!

Here's the code in case anyone wants it! I added a bit to the original to not give me any points and a few other bits.

javascript:function splt(){s=document.body.innerHTML;nOffset=s.indexOf("Points must total ");nPoinx=parseInt(s.substr(nOffset+17,4));aLizards=new Array();aEdBoxIDs=new Array();nCnt=0;for(j=0;j<document.anchors.length;j++){s=document.anchors[j].parentNode.innerHTML;n=s.indexOf('points_');sEdboxID=s.substr(n,15);n=s.indexOf('Comment from');s=s.substr(n,n+60);nNameStart=s.indexOf('>')+1;nNameEnd=s.indexOf('</');sLzrd=s.substring(nNameStart,nNameEnd);if(aLizards.toString().indexOf(sLzrd)==-1&&sLzrd!="PaulCaswell"){aEdBoxIDs[nCnt]=sEdboxID;aLizards[nCnt++]=sLzrd;};}nPoinxPerLizard=parseInt(nPoinx/aLizards.length);for(j=0;j<aLizards.length;j++){document.getElementsByName(aEdBoxIDs[j])[0].value=nPoinxPerLizard;}nAssigned=nPoinxPerLizard*aLizards.length;if(nAssigned!=nPoinx){alert('Leftover:'+(nPoinx-nAssigned)+' poinx!!!')};}splt();

Paul