簡體   English   中英

如何獲取和使用當前窗口URL?

[英]How to get current window URL and use it?

我想使用JavaScript獲取當前窗口位置,並在以下代碼中使用它:

<img src="http://shook.eu.org/qrc.php?text=CURRENT_WINDOW_URL" />

如果要從字符串構建html:

  var img = '<img src="http://shook.eu.org/qrc.php?text=' + encodeURI(window.location.href) + '" />'; document.body.innerHTML = img; 

編輯:你應該encodeURI你想傳遞的字符串。

 var url = window.location.href; var img = '<img src="http://shook.eu.org/qrc.php?text='+url+'" />'; $('#img').html(img); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="img"></div> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM