Hàm encodeURI() mã hóa một URI hoàn chỉnh bằng cách thay thế các ký tự đặc biệt (trừ các ký tự dành riêng cho URI như: , / ? : @ & = + $ #) bằng các dãy thoát (escape sequences) dạng %XX. Dùng cho URL đầy đủ.
Cú pháp
Cú pháp của nó như sau:
encodeURI(uri)
Ví dụ
<html> <head> <title>Ví dụ JavaScript</title> </head> <body> <script type="text/javascript"> var result1 = encodeURI('https://www.qries.com/?x=шеллы'); document.write(result1); document.write("<br>"); var result2 = encodeURI('https://www.tutorialspoint.com/?x=шеллы'); document.write(result2); </script> </body> </html>
Kết quả
https://www.qries.com/?x=%D1%88%D0%B5%D0%BB%D0%BB%D1%8B https://www.tutorialspoint.com/?x=%D1%88%D0%B5%D0%BB%D0%BB%D1%8B
Lưu ý: encodeURI() không mã hóa các ký tự: A-Z a-z 0-9 ; , / ? : @ & = + $ # - _ . ! ~ * ' ( )