JavaScript API: Browser Object

From DevWiki

Revision as of 18:52, 1 February 2010 by Riegersn (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Back to API Reference


Contents


browser object

The browser object allows you to communicate directly with the currently loaded page. Anything here is executed in regards to the entire browser window. If you want to work soley on a widget for things like click and mousMove, please see Widget Object


execute

string execute(string)
Execute javascript code on the active page.
loc = browser.execute("document.cookies");
browser.execute("document.getElementById('mplayer').pause();")


navigate

void navigate(string)
Navigates the player to a new url.
browser.navigate("http://www.browser.tv/");


invalidate

void invalidate(void)
Force the browser to redraw. This will not always work.
browser.invalidate();


resize

void resize(integer width, integer height)
Resize the browser viewable area
browser.resize(600,400);


setCookie

void setCookie(string)
Set a cookie in the active browser. Pass parameter in format of key=value
browser.setCookie("loggedinuser=username");


getLocation

string getLocation(void)
Returns the current location of the browser (url)
currentURL = browser.getLocation();


focus

bool focus(void)
Returns true if the browser is in focus
if ( browser.focus() ) { ... }


mouseMove

void mouseMove(int x, int y)
Takes the specificed x/y coordinates and moves the mouse to that location.
browser.mouseMove(40, 60);


click

void click(int)
Takes the specificed key code coordinates and clicks the mouse at that location.
browser.click(browser.KEY_BACKSPACE);
Below is a list of predefined constants you can use:
  • browser.KEY_BACKSPACE
  • browser.KEY_TAB
  • browser.KEY_RETURN
  • browser.KEY_SHIFT
  • browser.KEY_CONTROL
  • browser.KEY_ALT
  • browser.KEY_CAPSLOCK
  • browser.KEY_ESCAPE
  • browser.KEY_SPACE
  • browser.KEY_PAGEUP
  • browser.KEY_PAGEDOWN
  • browser.KEY_END
  • browser.KEY_HOME
  • browser.KEY_LEFT
  • browser.KEY_UP
  • browser.KEY_RIGHT
  • browser.KEY_DOWN
  • browser.KEY_INSERT
  • browser.KEY_DELETE
  • browser.KEY_F1
  • browser.KEY_F2
  • browser.KEY_F3
  • browser.KEY_F4
  • browser.KEY_F5
  • browser.KEY_F6
  • browser.KEY_F7
  • browser.KEY_F8
  • browser.KEY_F9
  • browser.KEY_F10
  • browser.KEY_F11
  • browser.KEY_F12
  • browser.KEY_NUMLOCK
  • browser.KEY_SCROLLLOCK
  • browser.KEY_META


keyPress

void keyPress(int)
Takes the specificed key code and executes this on the page.
Same as browser.click() which is the preferred method.
browser.keyPress(browser.KEY_BACKSPACE);


keyUp

void keyUp(void)
Simulates arrow key up
browser.keyUp();


keyDown

void keyDown(void)
Simulates arrow key up
browser.keyDown();


mouseDown()

void mouseDown(int x, int y)
Simulates mouse down
browser.mouseDown();


mouseUp()

void mouseUp(int x, int y)
Simulates mouse up
browser.mouseUp(x, y);


mouseWheelLeft

void mouseWheelLeft(void)
Simulates the mousewheel Left action
browser.mouseWheelLeft();


mouseWheelRight

void mouseWheelRight(void)
Simulates the mousewheel Right action
browser.mouseWheelRight();


mouseWheelPageLeft

void mouseWheelPageLeft(void)
Simulates the mousewheel PageLeft action
browser.mouseWheelPageLeft();


mouseWheelPageRight

void mouseWheelPageRight(void)
Simulates the mousewheel PageRight action
browser.mouseWheelPageRight();


mouseWheelUp

void mouseWheelUp(void)
Simulates the mousewheel Up action
browser.mouseWheelUp();


mouseWheelDown

void mouseWheelDown(void)
Simulates the mousewheel Down action
browser.mouseWheelDown();


mouseWheelPageUp

void mouseWheelPageUp(void)
Simulates the mousewheel PageUp action
browser.mouseWheelPageUp();


mouseWheelPageDown

void mouseWheelPageDown(void)
Simulates the mousewheel PageDown action
browser.mouseWheelPageDown();


getMeta

string getMeta(string)
Returns the value of the given metadata tag on the page.
browser.getMeta("description");


reload

void reload(void)
Reload/refresh the active page
browser.reload()


setConfigInt

void setConfigInt(string key, string value)
Sets configuration in the browser. Same as editing about:config in the firefox browser.
browser.setConfigInt("browser.link.open_external", "3")


setConfigBool

void setConfigBool(string key, string value)
Sets configuration in the browser. Same as editing about:config in the firefox browser.
browser.setConfigBool("browser.display.show_image_placeholders", "true")


setConfigChar

void setConfigChar(string key, string value)
Sets configuration in the browser. Same as editing about:config in the firefox browser.
browser.setConfigChar("image.animation_mode", "normal")
Personal tools