如何获取当前窗口URL并使用它?

时间:2015-07-07 14:18:24

标签: javascript

我想使用JavaScript获取当前窗口位置,并在以下代码中使用它:

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

2 个答案:

答案 0 :(得分:1)

如果要从字符串构建html:

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

    document.body.innerHTML = img;

编辑:您应该encodeURI要传递的字符串。

答案 1 :(得分:0)

&#13;
&#13;
var url = window.location.href;

var img = '<img src="http://shook.eu.org/qrc.php?text='+url+'" />';

$('#img').html(img);
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="img"></div>
&#13;
&#13;
&#13;