我有一个SharePoint应用程序,可以从库中检索页面内容,并为桌面和移动站点提供数据。我们在页面中也有链接,我如何用普通的JavaScript呈现HTML模板?
例如,我们有两个来自页面内容的页面链接:
<a class="template" href="/3.aspx">
我想添加的href前面的http://<sitename>/pages/
或http://<sitename>/pages/m/
取决于屏幕大小或设备。
我如何通过vanilla JS实现这一点?
发布于 2018-09-25 04:56:31
有了一个名为lit-html的轻量级库,事情就简单了:
import { html, render } from 'https://unpkg.com/lit-html/lit-html.js?module';
const linkTemplate = orientation =>
html`<a href="https://<sitename>/pages/{orientation != null ? 'm/' : '/'}3.aspx">Link text</a>`
render(linkTemplate(window.orientation), container)
发布于 2018-09-25 02:04:56
屏幕大小方式:
function isMobile() {
return window.innerWidth < 800;
}
var mobileUrl = 'http://<sitename>/pages/m/1.html';
var desktopUrl = 'http://<sitename>/pages/index.html';
window.location = isMobile() ? mobileUrl : desktopUrl;
更优雅的“鸭式”移动支票
function isMobile() {
return typeof window.orientation !== 'undefined';
}
还有一种分析navigator.userAgent
值的方法
https://stackoverflow.com/questions/52482642
复制相似问题