Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537
hrome 126 于近期發布了穩定版本,其中一個比較有意思的更新是給 HTML 帶來一個新的元素:<permission> ,它將從這個版本開始試用,并且正在努力走向標準化。
今天我們一起來看下這個 <permission> 元素的用法。
當 Web 應用程序需要訪問瀏覽器的高級功能時,需要向用戶主動請求許可。例如,當百度地圖使用 Geolocation API 獲取用戶的地理位置時,瀏覽器會提示用戶申請權限,這是權限規范中定義明確的概念。
申請權限的觸發方式一般分為兩類,被動隱式觸發,或者主動顯示觸發:
例如,Geolocation API 是一個強大的 API,它的使用依賴于首次使用時隱式詢問的方法。例如,當程序調用 navigator.geolocation.getCurrentPosition() 方法時,權限提示框會在第一次調用時自動彈出,還有另外一個例子是 navigator.mediaDevices.getUserMedia()。
一些其他的 API,如 Notification API 或 Device Orientation API,通常有一種顯式的方式通過靜態方法來請求權限,如 Notification.requestPermission() 或 DeviceMotionEvent.requestPermission()。
網站可以在加載時立即調用諸如 navigator.mediaDevices.getUserMedia() 或 Notification.requestPermission() 等方法。這會導致在用戶還沒與網站進行交互時就彈出權限提示。這就是明顯的權限濫用行為,并且影響到兩種方式,既包括首次使用時的隱含詢問,也包括提前明確請求。
權限濫用導致瀏覽器廠商要求有像點擊按鈕或按下按鍵這樣的用戶操作,然后才會顯示權限提示。這種方法的問題在于,瀏覽器很難確定某個特定的用戶操作是否應該導致顯示權限提示。也許用戶只是因為頁面加載時間太長而在頁面上隨意某個地方隨便點擊,有些網站也變得非常擅長誘騙用戶點擊內容來觸發提示。
另一個問題是權限提示框通常顯示的方式:在網站的 “死亡線” 之上(特別是在大屏幕上),也就是說,在應用程序能夠繪制到的瀏覽器窗口區域之外。用戶在剛剛點擊了窗口底部的一個按鈕后,可能會錯過瀏覽器窗口頂部的提示,這種情況還是挺常見的。當瀏覽器有應對權限濫用的緩解措施時,這個問題往往會更加嚴重。
另外,用戶一旦做出了拒絕某個權限的操作,之后想要改變就不太容易了。他們得找到特定的地方,比如那個網站信息下拉菜單,然后去進行重置或調整權限的操作,而且還得重新加載頁面才行。網站也沒辦法提供很方便的途徑讓用戶快速改變權限狀態,還得詳細地告訴用戶怎么去找到地方改變設置。
如果某個權限是非常重要的,比如視頻會議軟件要用麥克風權限,那像谷歌會議這類的軟件就會彈出很顯眼的對話框來告訴用戶怎么去把之前阻止的權限給開通。
為了解決上面的這些問題,<permission> 元素誕生了。這個元素允許開發者以聲明方式請求使用權限,如下例所示:
<permission type="camera" />
“type” 屬性代表你正在請求的權限列表(如果有多個可以以空格分割)。目前,允許的值是 'camera','microphone' 以及 'camera microphone'。默認情況下,這個元素呈現出來的樣子類似于具有最簡用戶代理樣式的按鈕。
對于某些允許附加參數的權限,type-ext 屬性接受以空格分隔的鍵值對,例如 precise:true 地理位置權限。
當用戶與 <permission> 元素交互時,他們可以循環經歷各個階段:
如果他們之前不允許某項功能,他們可以在每次訪問時允許該功能,或者在當前訪問時允許該功能。
如果他們之前允許該功能,他們可以繼續允許,或者停止允許。
如果他們之前不允許某項功能,他們可以繼續不允許它,或者這次允許它。
<permission> 元素的文本會根據狀態自動更新。例如,如果已授予使用某項功能的權限,則文本會更改為表示允許使用該功能。如果需要先授予權限,則文本會更改為邀請用戶使用該功能。將之前的屏幕截圖與以下屏幕截圖進行比較,以查看這兩種狀態。
<permission> 元素可以與 Permissions API 一起使用。有許多事件可供監聽:
我們可以直接在 HTML 代碼中內聯注冊這些事件的事件監聽器(<permission type="…" onpromptdismiss="alert('The prompt was dismissed');" />),或者在 <permission> 元素上使用 addEventListener():
<permission type="camera" />
<script>
const permission = document.querySelector('permission');
permission.addEventListener('promptdismiss', showCameraWarning);
function showCameraWarning() {
// Show warning that the app isn't fully usable
// unless the camera permission is granted.
}
const permissionStatus = await navigator.permissions.query({name: "camera"});
permissionStatus.addEventListener('change', () => {
// Run the check when the status changes.
if (permissionStatus.state === "granted") {
useCamera();
}
// Run the initial check.
if (permissionStatus.state === "granted") {
useCamera();
}
});
</script>
參考:https://developer.chrome.com/blog/permission-element-origin-trial
天給大家介紹一個非常好用的前端插件jQuery UI。
jQuery UI是以 jQuery 為基礎的開源 JavaScript 網頁用戶界面代碼庫。包含底層用戶交互、動畫、特效和可更換主題的可視控件。
下面是一個以jQuery UI實現的彈出登錄框功能,代碼非常簡單。
<!DOCTYPE html>
<html>
<head>
<title> new document </title>
<meta charset="utf-8">
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/jquery-ui.css">
</head>
<body>
<h1>jQueryUI:Widgets —— Dialog</h1>
<h3>彈出式對話框</h3>
<a id="btn-login" class="btn btn-success" href="#">我要登錄</a>
<div id="dialog-login" title="用戶登錄">
<form action="">
用戶名:<input type="text"><br>
密碼名:<input type="password"><br>
</form>
</div>
<script src="js/jquery-1.11.3.js"></script>
<script src="JS/jquery-ui.js"></script>
<script>
var $dialog=$("#dialog-login")
$dialog.dialog({
autoOpen:false,
modal:false,
show:{effect:"blind",duration:1000},
hide:{effect:"explode",duration:1000},
buttons:{
"登錄":()=>setTimeout(()=>{
alert("登錄成功");
$dialog.dialog("close");
},1000),
"取消":()=>$dialog.dialog("close")
},
close(){
$("form").get(0).reset()
}
});
$("#btn-login").click(()=>{
$dialog.dialog("open")
})
</script>
</body>
</html>
天給大家推薦一款超美觀的pc端vue.js彈窗組件VueJsModal。
vue-js-modal 基于Vue構建的Modal對話框組件。單獨組件,方便使用。支持拖拽、縮放、異步調用組件。
安裝
$ npm i vue-js-modal -S
引入組件
// 在main.js中引入
import Vue from 'vue'
import VModal from 'vue-js-modal'
import 'vue-js-modal/dist/styles.css'
Vue.use(VModal)
調用方式
<template>
<modal name="example"
:width="300"
:height="300"
:resizable="true"
:draggable="true"
:adaptive="true"
@before-open="beforeOpen"
@opened="Opened"
@before-close="beforeClose"
@closed="Closed"
>
Hello, VueModal!
</modal>
</template>
<script>
export default {
data() {
return {}
},
mounted() {
this.$modal.show('example')
},
methods: {
beforeOpen(event) {
console.log('Opening...')
},
Opened(event) {
console.log('Opened...')
},
beforeClose(event) {
console.log('Closing...')
},
Closed(event) {
console.log('Closed...')
}
}
}
</script>
調用內部 show、hide 方法顯示和隱藏彈窗
<template>
<modal name="my-first-modal">
This is my first modal
</modal>
</template>
<script>
export default {
mounted () {
this.show()
},
methods: {
show () {
this.$modal.show('my-first-modal');
},
hide () {
this.$modal.hide('my-first-modal');
}
}
}
</script>
另外還支持Modal動態調用組件
import MyComponent from './MyComponent.vue'
this.$modal.show(
MyComponent,
{ text: 'This text is passed as a property' },
{ draggable: true }
)
// or
this.$modal.show(
{
template: `
<div>
<h1>This is created inline</h1>
<p>{{ text }}</p>
</div>
`,
props: ['text']
},
{ text: 'This text is passed as a property' },
{ draggable: true, resizable: true },
{ 'before-close': event => {} }
)
附上模態框示例及倉庫地址
# demo地址
http://vue-js-modal.yev.io/
# 項目地址
https://github.com/euvl/vue-js-modal
ok,這次就分享到這里。如果大家有其它Vue彈窗組件,歡迎留言討論~
*請認真填寫需求信息,我們會在24小時內與您取得聯系。