Reputation: 158
<script src="https://code.jquery.com/jquery-3.0.0.js"></script>
<script type="text/javascript">
var link = $('#unique_link').html();
var vk_link = "http://vk.com/share.php?url="+link+"&title=text";
</script>
<a onclick="window.open(vk_link,'_blank', 'scrollbars=0, resizable=1, menubar=0, left=100, top=100, width=550, height=440, toolbar=0, status=0');return false">LINK</a>
But in browser I see undefined, not replaced variable: window.open(vk_link, ....
How to fix it?
Upvotes: 2
Views: 1705
Reputation: 467
You can also use the HREF attribute with javascript: keyword in Anchor Tag to call a JavaScript function:
<a href="javascript:window.open(vk_link,'_blank', 'scrollbars=0, .......">Link</a>
Upvotes: 2
Reputation: 3774
You're trying to access vk_link
in a string which will not be evaluated to its value. Just define a function let's say openWindow
and call it on onClick
instead like below.
<script src="https://code.jquery.com/jquery-3.0.0.js"></script>
<script type="text/javascript">
var link = $('#unique_link').html();
var vk_link = "http://vk.com/share.php?url="+link+"&title=text";
function openWindow(){
window.open(vk_link,'_blank', 'scrollbars=0, resizable=1, menubar=0, left=100, top=100, width=550, height=440, toolbar=0, status=0');
}
</script>
<a onclick="openWindow()">LINK</a>
Hope this helps !
Upvotes: 2