Using this code, I am able to select all external links and make it so they open in a new tab:
$.expr[':'].external = function(obj){
return !obj.href.match(/^mailto\:/)
&& (obj.hostname != location.hostname)
&& !obj.href.match(/^javascript\:/)
&& !obj.href.match(/^$/)
};
$('a:external').attr('target', '_blank');
Is there a way that I can modify that
so it does this function:
var newwindow; function poptastic(url){
newwindow=window.open(url,'name', 'height=800,width=1020,scrollbars=yes');
if (window.focus) {newwindow.focus()}}
Ultimately I want it to just do the bottom function, but to all external links instead of having to go in and add this to each external link:
<a href="javascript:poptastic('http://www.external-link.com')">External Link</a>
(I know that some people don’t like this, requiring the user to have a new window popped open instead of just doing target=”_blank”, but I have asked a small group of users in the age group for my client’s site, and they all preferred this method greatly over it opening in a new tab).
Also, is there a way that I can add to the top part so any .PDF files will also do the above command? Its set up so its only for external sites, but could you make an exception for any .pdf too?
Thanks so much guys!
That is, on click of any of the external links prevent the default click behaviour (which would of course be to navigate to the specified url, replacing the current page), and instead call your
poptastic()function passing the href.(You could just put the body of your
poptasticdirectly into the.clickhandler…)EDIT: To do the same for PDF, if your intention is to modify the
:externalselector to include PDFs – where I’m defining “PDF” as being an href ending in".pdf"– you could do this:DEMO: http://jsfiddle.net/RevXG/4/