<?xml version="1.0" encoding="UTF-8"?> <xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xe="http://www.ibm.com/xsp/coreex"> <xp:button id="button1" value="UserAgent取得(CSJS)"> <xp:eventHandler event="onclick" submit="false"> <xp:this.script><![CDATA[ document.getElementById("#{id:inputText1}").value = window.navigator.userAgent.toLowerCase(); document.getElementById("#{id:inputText2}").value = window.navigator.appVersion.toLowerCase(); ]]></xp:this.script> </xp:eventHandler> </xp:button> <xp:br></xp:br><xp:button id="button2" value="ブラウザ判定(SSJS)"> <xp:eventHandler event="onclick" submit="true" refreshMode="complete"> <xp:this.action><![CDATA[#{javascript:var ua = getComponent("inputText1").getValue(); var ver = getComponent("inputText2").getValue(); var name = 'unknown'; if (ua.indexOf("msie") != -1){ if (ver.indexOf("msie 6.") != -1){ name = 'ie6'; }else if (ver.indexOf("msie 7.") != -1){ name = 'ie7'; }else if (ver.indexOf("msie 8.") != -1){ name = 'ie8'; }else if (ver.indexOf("msie 9.") != -1){ name = 'ie9'; }else if (ver.indexOf("msie 10.") != -1){ name = 'ie10'; }else{ name = 'ie'; } }else if(ua.indexOf('trident/7') != -1){ name = 'ie11'; }else if(ua.indexOf('edge') != -1){ name = 'edge'; }else if (ua.indexOf('chrome') != -1){ name = 'chrome'; }else if (ua.indexOf('safari') != -1){ name = 'safari'; }else if (ua.indexOf('opera') != -1){ name = 'opera'; }else if (ua.indexOf('firefox') != -1){ name = 'firefox'; } print(name); getComponent("inputText3").setValue(name);}]]></xp:this.action> </xp:eventHandler> </xp:button><xp:br></xp:br> <xp:br></xp:br> <xp:inputText id="inputText1" style="width:500px"> userAgent : </xp:inputText> <xp:br></xp:br> <xp:inputText id="inputText2" style="width:500px"> appVersion : </xp:inputText> <xp:br></xp:br> <xp:inputText id="inputText3">ブラウザ :</xp:inputText><xp:br></xp:br> </xp:view>
CSJSで取得したUserAgent情報を、SSJSで計算して、ブラウザ情報を画面に表示させるサンプルとなります。