いいね!数

0

閲覧数
243


xPagesで表示させた結果をセキュリティ的にテキストコピー禁止にしたい文章があります
調べた所CSSやJavaScriptを使った方法など何種類かあるようですが通常のHTMLで

<body onMouseDown="return false;" onSelectStart="return false;" onCopy="return false;" unselectable="on">

と同じことをxPagesで行おうとして以下のような感じでxPagesのソースを書きました。
 
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
 <xp:this.attrs>
  <xp:attr name="onMouseDown" value="return false"></xp:attr>
  <xp:attr name="onSelectStart" value="return false"></xp:attr>
  <xp:attr name="onCopy" value="return false"></xp:attr>
  <xp:attr name="unselectable" value="on"></xp:attr>
 </xp:this.attrs>
コピー禁止
</xp:view>

ブラウザ上である程度は思ったような動きににはなりました、
しかしブラウザで変換されたHTMLのソースコードを見ると

<!DOCTYPE html>
<html lang="ja" onMouseDown="return false" onSelectStart="return false" onCopy="return false" unselectable="on">
(中略)

<body class="xspView tundra">

(中略)

</body>
</html>

というような感じで<body>タグでなく<html>タグの方で変換されています。
これを<body>タグの方にしようとしましたがどうもxPagesの方ではダメなようです。

他の方はこういったxPagesを使った場合のコピー禁止の措置はどいう方法でコードを書かれているのでしょうか?

サーバー情報: | クライアント情報: | 
カテゴリ:アプリ開発 - XPages | タグ:
  | 質問日時:2017/04/07 12:33:24

回答・コメント

いいね!数

0

自己解決とりあえず下記の手法で目的の動きまで出来ました。

test.css記述
.disable-select {
 user-select: none;
 -moz-user-select: none;
 -webkit-user-select: none;
 -ms-user-select: none;
}

xPages記述
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
 styleClass="disable-select">
 コピー禁止
 <xp:this.resources>
  <xp:styleSheet href="/test.css"></xp:styleSheet>
 </xp:this.resources>
 <xp:eventHandler event="onClientLoad" submit="false">
  <xp:this.script><![CDATA[
document.body.setAttribute('onMouseDown', 'return false');
document.body.setAttribute('onSelectStart', 'return false');
document.body.setAttribute('onCopy', 'return false');
document.body.setAttribute('unselectable', 'on');]]></xp:this.script>
 </xp:eventHandler>
</xp:view>

参考URL
Take control of your XPages  Oval Business Solutions  Home
https://www.ovalbusinesssolutions.co.uk/single-post/2016/08/08/Take-control-of-your-XPages

Html body attributes converted into XPages - Stack Overflow
http://stackoverflow.com/questions/19463369/html-body-attributes-converted-into-xpages

回答日時:2017/04/11 7:02:45