Ok, so i'm finally stepping out of the z80 asm help section to ask for some help of my own. What i want to do is write a Firefox bookmark that will let me type in a keyword followed by a word, then pass that word to a dictionary website and get the definition.

For Firefox, normally i will create a bookmark, eg. http://www.wordreference.com/fren/%s, give it the keyword fren, and then to get a French to English definition i can type "fren salut" in the URL bar.

However, the website i'm trying to use now seems a bit more complicated, it uses frames for one. I found the page sercxu.pl which lets me add a value like i normally would, (http://reta-vortaro.de/cgi-bin/sercxu.pl?sercxata=helpi), but it doesn't send the information. Also, since the information is loaded in the other frame, nothing happens when i click "trovu" (find). I've written a small script that will fill out the form on the homepage and send it:

Code:
window.frames[1].document.forms[0].sercxata.value="helpi";
window.frames[1].document.forms[0].submit();

However, where i'm having trouble is opening the website and filling in the form once the site has loaded. The problem is that the code above gets run before the other page loads, so nothing happens. Here's the full code i've got so far:

Code:
javascript:window.location="http://reta-vortaro.de/revo/";
window.frames[1].document.forms[0].sercxata.value="helpi";
window.frames[1].document.forms[0].submit();

If anyone's got any ideas (or a way that works), please let me know Very Happy
The basic idea is to add an event listener for when the page finished loading.
You can do that with something like this:

Code:

window.addEventListener('load',function(){
    // your code here
},false);

EDIT: perhaps you also have to wait until the frames have loaded, i never dealt with frames before. My guess would be doing something like window.frames[1].addEventListener blahblahblah
Thanks for the reply, but i can't seem to get that to work from the URL bar... The code i put in between the brackets doesn't get run. It just says "Undefined" in the console, but i'm not sure what is undefined. Something in addEventListener, i think.

EDIT: OK, i got this to work by using GreaseMonkey to run the script after the page loads. I use a bookmark in Firefox to be able to type from the URL bar, for example for the Lernu dictionary i can type "leo + word", for example "leo helpi". It turns that into "http://eo.lernu.net/cgi-bin/vortaro.pl?word=helpi". Then my script:

Code:
var entry = getUrlVars()["word"];

document.getElementById('modelo').value = entry;

function getUrlVars() {
    var vars = {};
    var parts = window.location.href.replace(/[?]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
        vars[key] = value;
    });
    return vars;
}
...does its magic.

The Reta Vortaro was a bit more complicated, i ended up just using a short delay before running the script:

Code:
var entry = getUrlVars()["word"];

window.setTimeout(my_func, 100);

function my_func() {
    window.frames[1].document.forms[0].sercxata.value = entry;
    window.frames[1].document.forms[0].submit();
}

function getUrlVars() {
    var vars = {};
    var parts = window.location.href.replace(/[?]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
        vars[key] = value;
    });
    return vars;
}


Anyway, now i can look up stuff in both dictionaries by searching from the URL bar Very Happy
Raceconditions are a very bad programming style Sad
And what do you mean with from the url bar?
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement