java - How can I change Page Title periodically and switch the change on/off? -


i want change title of page periodically, i.e. add (*) in front of current page title , remove after couple of seconds. want turn title change on , off in code.

i , set page title from:

    public static native void setpagetitle(string title) /*-{     $doc.title = title;     }-*/;   public static native string getpagetitle() /*-{     return $doc.title; }-*/; 

but how should write function change page title every 300 miliseconds while adding , removing prefix?

what tried was:

private void changepagetitle(final string prefix) {      new timer() {         @override         public void run() {             string pagetitle =getpagetitle();              if (pagetitle.startswith(prefix)) {                     pagetitle = pagetitle.substring(prefix.length());                 }                 else {                     pagetitle = pagetitle + prefix;                 }             setpagetitle(pagetitle);          }         }     }.schedule(300); } 

this not work. , not know how switch process on , off?

the effect should in facebook. when new message arrive , not on facebook browser tab, tab shows notification blinking.

you have change schedule(300) schedulerepeating(300).

you should use 1 instance of timer or save last timer cancel before creating new one.

btw: dont need write jsni access window title, use window.gettitle() , window.settitle(string)

edited:

this should work:

// create instance of timer final myupdatetitletimer mytimer = new myupdatetitletimer(); // start updater mytimer.setprefix("> "); // stop set prefix null mytimer.setprefix(null);   class myupdatetitletimer extends timer {   private string prefix;   private string title;   private boolean b;    public void run() {     string s = (b = !b) ? prefix + title : title;     window.settitle(s);   }    public void setprefix(string prefix) {     if (title != null) {       window.settitle(title);     }     this.prefix = prefix;     if (prefix == null) {       cancel();     } else {       title = window.gettitle();       schedulerepeating(300);     }   } } 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -