Reputation:
I want to get current window location using JavaScript and use it in the following code:
<img src="http://shook.eu.org/qrc.php?text=CURRENT_WINDOW_URL" />
Upvotes: 1
Views: 226
Reputation: 923
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>
Upvotes: 0
Reputation: 5984
If you are building the html from a string:
var img = '<img src="http://shook.eu.org/qrc.php?text=' + encodeURI(window.location.href) + '" />';
document.body.innerHTML = img;
Edit: You should encodeURI
the string you want to pass.
Upvotes: 1