Since the inclusion of a browser widget in Livecode 8 I have been playing with getting the same Javascript to work in that environment.
The widget environment is different but I have found that it is actually easier than using revBrowserCEF and revBrowserExecute().
Buried in the script is a little public function called OnDo which takes Javascript string and passes it off to a private Javascript handler.
You can find it buried in here
https://github.com/livecode/livecode/bl ... rowser.lcb at line 653.
It is as easy to use as
Code: Select all
Do "alert('Livecode is great');" in widget "Browser"
Since Javascript cares not a whit about whitespace you can write multiple commands in a single line. A good place to look at Javascript obfuscated by removing the whitespace and renaming functions and variables is the source of Google's start page.
For this exercise though this example works fine, well it does for me using LC 8.0 Dp 16 on a Mac. I have no reason to believe that it wouldn't work for you but let me know if it doesn't.
Code: Select all
Do "var txt = document.getElementById('nav').innerHTML; var res = txt.replace('Lost your password?','<span id=clk>$&</span>');document.getElementById('nav').innerHTML = res;" in widget "Browser"
You don't have to do it this way though, Javascript in your widget remembers the variables you so you can do the same thing this way.
Code: Select all
Do "var txt = document.getElementById('nav');" in widget "Browser"
Do "var res = txt.replace('Lost your password?','<span id=clk>$&</span>');" in widget "Browser"
Do "document.getElementById('nav').innerHTML = res;" in widget "Browser"
As long as each section of Javascript is complete in itself this will work fine.
Which is how you would make the Lost your password? link on a Wordpress login page into a programatically clickable link.
You can click the link like this
Code: Select all
Do document.getElementById('clk').click();" in widget "Browser"
If you know how many links you have on a page and the number of the link you want to change you can do this
Code: Select all
Do "document.getElementsByTagName('a')[1].innerHTML='<span id=clk>Found your password</span>';" in widget "Browser"
If you don't know how many links you have then this will find the one you want.
Code: Select all
Do "var linkz = document.getElementsByTagName('a');" in widget "Browser"
Do "for(var i = linkz.length; i--; ){ var dex = linkz[i].innerHTML; ind = dex.toString().search('Lost your password?'); alert(ind); }" in widget "Browser"
I haven't yet found something I can't do with Javascript and this Do function but you do need to remember that you have to set the Javascript as strings. Javascript fails silently so you won't get any response if your code fails.
I test in Brackets as I can see the Javascript errors with this tool.
I hope this is useful for you.