user5089907
user5089907

Reputation:

How to get current window URL and use it?

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

Answers (2)

Keerthi
Keerthi

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

KJ Price
KJ Price

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

Related Questions