當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


p5.js getURLParams()用法及代碼示例

getURLParams()函數用於將當前URL參數返回到JavaScript對象,每個參數均作為對象的單獨成員。

用法:

getURLParams()

參數:該函數不接受任何參數。


返回值:它返回路徑參數的對象。

下麵的示例說明了p5.js中的getURLParams()函數:

例:

function setup() { 
  createCanvas(500, 200); 
  
  // get the url path as array 
  urlParamsObject = getURLParams(); 
  
  textSize(16); 
  text("The URL is:http://example.com?height=100&width=500&type=box", 
    10, 20); 
  
  text("The URL parameters are:", 10, 60); 
  
  text("Type parameter:" + urlParamsObject["type"], 10, 80); 
  text("Height parameter:" + urlParamsObject.height, 10, 100); 
  text("Width parameter:" + urlParamsObject.width, 10, 120); 
  
  // display the array in the console 
  console.log(urlParamsObject); 
}

輸出:

  • 顯示對象的屬性:
    path-obj-display
  • 在控製台中查看對象:
    path-obj-console

在線編輯: https://editor.p5js.org/
環境設置: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/

參考: https://p5js.org/reference/#/p5/getURLParams



相關用法


注:本文由純淨天空篩選整理自sayantanm19大神的英文原創作品 p5.js | getURLParams() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。