osx - OS X Web View App - Is it possible to use the native Preferences panel to adjust JavaScript variables? -
i wrote app in html5/javascript , embedded os x web view. works , has settings area built web app works.
my question is, possible utilize native os x style preferences panel (app name > preferences) adjust settings of web app?
the web app uses javascript variables settings. os x preferences panel have read javascript variables, allow them adjusted, , update them upon save.
example web code (test.html):
<p>number of widgets (sample setting): <input type="button" id="buttonlesswidgets" value="<"> <span id="divnumwidgets"></span> <input type="button" id="buttonmorewidgets" value=">"> </p> <script> var numwidgets = 10; // display current number of widgets when app opened document.getelementbyid("divnumwidgets").innerhtml = numwidgets; // adjust sample setting --- part i'm hoping move preferences panel buttonlesswidgets.onclick = function() { numwidgets -= 1; divnumwidgets.innerhtml = numwidgets; }; buttonmorewidgets.onclick = function() { numwidgets += 1; divnumwidgets.innerhtml = numwidgets; }; </script> is implement? i'm comfortable html5 , javascript new xcode.
it possible, it'd require work on end, , there's no automatic way it. implementing custom preferences pane, that's outside scope of single question, , can find materials elsewhere. however, actual javascript part isn't bad.
the webview class provides windowscriptobject method can phone call obtain reference javascript environment. can utilize standard setvalue:forkey: , valueforkey: methods , set global variables in javascript context.
you can inject these values page before it's loaded providing custom webframeloaddelegate web view's setframeloaddelegate: method, , utilizing webscriptobject context passed webview:didclearwindowobject:forframe: delegate method. method called javascript context available, before page loads, allow insert custom preference variables.
osx cocoa webview
No comments:
Post a Comment