Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
43
rated 0 times [  50] [ 7]  / answers: 1 / hits: 22531  / 12 Years ago, tue, august 7, 2012, 12:00:00

How to click on a link to open a PDF in a new window while at the same time changing the parent window?



Something like? …



<a href=assets/pdf/a_pdf_doc.pdf target=new
onclick=window.parent.location.href='newpage.html';>A PDF Doc</a>


Of course the above doesn't work....just an example of what I perceive to be close to the answer. Thanks!


More From » html

 Answers
3

You could move the new window and the redirect functionality into a single JS function. Here's what that definition might look like:



<script type=text/javascript>

function openPdf(e, path, redirect) {
// stop the browser from going to the href
e = e || window.event; // for IE
e.preventDefault();

// launch a new window with your PDF
window.open(path, 'somename', ... /* options */);

// redirect current page to new location
window.location = redirect;
}

</script>


And then in your HTML:



<a href=assets/pdf/a_pdf_doc.pdf
onclick=openPdf(event, 'assets/pdf/a_pdf_doc.pdf', 'newpage.html');>
A PDF Doc
</a>


I would keep the regular href attribute specified in case a user has JS turned off.


[#83791] Monday, August 6, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
marcelofrankiea

Total Points: 200
Total Questions: 96
Total Answers: 101

Location: Tonga
Member since Tue, Nov 30, 2021
3 Years ago
;