Reputation: 1
I have two links:
<div class="holder_content1" id="link" >
<p> <a href="PDFJS/pdfFile/Tut02_v2-Ans.pdf" onclick="getPDFpath()">Tut02_v2-Ans</a>
<p><a href="PDFJS/pdfFile/DA_Chap02_v3.pdf" onClick="getPDFpath()">DA_Chap02_v3</a>
I need to get link from anchor attribute using Javascript. Here is my javascript function.
function getPDFpath(){
var path = document.getElementById('link');
var s = path.getAttribute('a');
alert(s.href);
}
Need link after pressing click. Thank you
Upvotes: 0
Views: 1665
Reputation: 43718
Pass the link reference to the getPDFpath
function.
<a href="PDFJS/pdfFile/DA_Chap02_v3.pdf" onClick="getPDFpath(this)">DA_Chap02_v3</a>
You can now access the href
property of the element.
function getPDFpath(link){
//navigate to another page by passing the href as the `pdflink` query param.
location.href = 'my_other_page.html?pdflink=' + encodeURIComponent(link.href);
}
However, you don't have to use any javascript code to do this:
<a href="my_other_page.html?pdflink=PDFJS/pdfFile/DA_Chap02_v3.pdf">DA_Chap02_v3</a>
Upvotes: 1
Reputation: 2488
Here are functions to set and get cookies.
function setCookie(key, value, exdays) {
var exdate = new Date();
exdate.setDate(exdate.getDate() + exdays);
value = escape(value) + ((exdays === undefined) ? "" : "; expires=" + exdate.toUTCString());
document.cookie = key + "=" + value + '; path=/';
}
function getCookie(key) {
var i, x, y,
ARRcookies = document.cookie.split(";");
for (i = 0; i < ARRcookies.length; i++) {
x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
x = x.replace(/^\s+|\s+$/g,"");
if (x == key) {
return unescape(y);
}
}
}
Upvotes: 0