2014-01-12 215 views
1

我想打電話給js函數在vaadin代碼執行字符串:Vaadin和JS功能

String js = "function returnURL{" + 
       "return(window.location.href.replace(/(\\d+)$/, function(str, p1, p2) {" + 
        "return((Number(p1) + 1) + p2);" + 
       "}));" + 
      "}"; 

如何exacly通過這種方式調用這個函數:

Page.getCurrent().getJavaScript().execute(javascript function); 

回答

3

你有一個小錯誤在你的js代碼,你應該有:

String js = "function returnURL(){" + //Check the parens here 
      "return(window.location.href.replace(/(\\d+)$/, function(str, p1, p2) {" + 
       "return((Number(p1) + 1) + p2);" + 
      "}));" + 
     "}"; 

然後:

Page.getCurrent().getJavaScript().execute(js); 

希望這會有所幫助。歡呼聲