javascript - How to add a signIn button in a website and update it based on user authentication -


i working on playframework believe question more general topic of web implementation. creating website want put signin button on top right corner of home page , update based on user authentication.

i.e. if user logged in there my profile , logout button , if not there signin button. know how implement using different pages uses different routes, in case can load complete page don't want load complete page instead use popup window signin/signup , want user redirect on same page after signing in (click on signin -> signin form popup -> submit -> signed in) url shouldn't changing in process. have seen type of design in many popular websites don't know how build one.

i did research , found, can using jquery's ajax call. of ajax call can request data server in background (here request html) , update current page dom. in case supposed update dom of navbar's top right corner request html part don't know how it? new website designing, design or there other best way same task?

it appreciable if can tell me how should update link related css & js file page page. mean if css file not being used in particular page how remove reference , add new 1 relevant page.

sorry, if looks fool of asking such basic questions here want clear concept in web-designing , implementation. helpful if can suggest me book or link read these topics.

if understood question correctly, asking dom -part of equation?

here's example (see jsfiddle, whole thing, current code expects login button present @ launch):

function login (logtype) {     var insertinput = function (value) {         document.getelementbyid('logincontainer').insertbefore(         document.createelement('input'),         document.getelementsbytagname('input')[0]);         var newbutton = document.getelementsbytagname('input')[0];         newbutton.type = 'button';         newbutton.value = value;         if (value === 'logout') {             newbutton.onclick = function () {login('logout');};         }         if (value === 'login') {             newbutton.onclick = function () {login('login');};         }         if (value === 'myprofile') {             newbutton.onclick = function () {window.location.href='http://jsfiddle.net/user/b00t/fiddles/';};         }     },     deleteinput = function () {         document.getelementbyid('logincontainer').removechild(document.getelementbyid('logincontainer').lastchild);     };     if (logtype === 'login') {         var login = confirm('login?');         if (login) {             insertinput('myprofile');             insertinput('logout');             deleteinput();         }     }     else if (logtype === 'logout') {         var logout = confirm('logout?');         if (logout) {             insertinput('login');             deleteinput();             deleteinput();         }     } } 

jsfiddle


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -