四零语境前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.0 KiB

  1. <html>
  2. <head>
  3. <meta
  4. name="viewport"
  5. content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, viewport-fit=cover"
  6. />
  7. <title>富文本展示</title>
  8. <style type="text/css">
  9. html,body {
  10. margin: 0;
  11. padding: 0;
  12. width: 100%;
  13. height: 100%;
  14. overflow: hidden;
  15. }
  16. .content {
  17. color: #333;
  18. width: 100%;
  19. height: 100%;
  20. }
  21. .content img {
  22. max-width: 100%!important;
  23. }
  24. </style>
  25. </head>
  26. <body>
  27. <p id="content" class="content"></p>
  28. </body>
  29. <script type="text/javascript" src="./js/uni-webview-js@1.5.4.js"></script>
  30. <script type="text/javascript">
  31. var obj = {}
  32. window.onload = function () {
  33. var search = window.location.search.slice(1);
  34. var arr = search.split('&');
  35. for ( var i = 0; i < arr.length; i++ ) {
  36. var strs = arr[i].split('=');
  37. obj[strs[0]] = strs[1];
  38. }
  39. if ( obj.rich ) {
  40. setRichText(JSON.parse(decodeURIComponent(obj.rich)));
  41. if ( obj.pageType == 'scroll' ) {
  42. window.setTimeout(function () {
  43. uni.postMessage({
  44. data: {
  45. height: document.getElementById('content').scrollHeight + 100
  46. }
  47. });
  48. }, 100)
  49. }
  50. }
  51. }
  52. function setStyle (attribute, value) {
  53. document.getElementById('content').style[attribute] = value
  54. }
  55. function setRichText (richText) {
  56. document.getElementById('content').innerHTML = richText
  57. }
  58. function setFontFace (fontList) {
  59. let code = fontList.reduce((accumulator, currentValue) => {
  60. return accumulator + `@font-face { font-family: ${currentValue.fontFamily};src: url('${currentValue.src}'); }`;
  61. }, "");
  62. var style = document.createElement("style");
  63. style.type = "text/css";
  64. style.rel = "stylesheet";
  65. style.appendChild(document.createTextNode(code));
  66. var head = document.getElementsByTagName("head")[0];
  67. head.appendChild(style);
  68. }
  69. function triggerCustomClick (name, args) {
  70. uni.postMessage({
  71. data: {
  72. customClick: {
  73. name: name,
  74. args: args
  75. }
  76. }
  77. });
  78. }
  79. </script>
  80. </html>