How do I automatically create a new window, blog stylee?
July 21, 2007 11:48 AM   Subscribe

Blogger.com template query - I'm using the Minima Ochre template. What HTML can I add to the template to make all links open in a new window?

I love linking to interesting things I find as I trot round the web on my blog. However, I'd also like those interesting things to open in a new window/tab when the user clicks on the link.

I know I can add 'target="_blank" ' to the HTML of every link I make, but I don't want to have to do this for every link I create. I'd like to have some HTML in the template that will automatically create a "new window link" for me.

Is this possible? If so, how?
posted by Rabulah to Computers & Internet (10 answers total) 1 user marked this as a favorite
 
The following HTML code will enable you to open all of your links in a new window.

< base main>

Stick it between your < head> and < /head> tags.

(Remove the spaces there, but I think you knew that.)
posted by beaucoupkevin at 12:07 PM on July 21, 2007


Er. That didn't work.

<base target="main">
posted by beaucoupkevin at 12:08 PM on July 21, 2007


If you put this in the bottom of your html, right before the end of the body tag, this'll do the job. You can also modify it slightly and add a bit of logic to get a bit more control over what, exactly, becomes an external link.
<script>
var links = document.getElementsByTagName("a"); 
for (var i = 0; i < links.length; i++)br>
  { 
  links[i].target = 'ext' + i;
  }
</script>

posted by ph00dz at 1:10 PM on July 21, 2007


err... there's a weird br> in there. (Stupid previewer... you have failed me!)

Let's just try it this way:

var links = document.getElementsByTagName("a");
for (var i = 0; i < links.length; i++)br> {
links[i].target = 'ext' + i;
}
posted by ph00dz at 1:12 PM on July 21, 2007


Ugh. Please don't make my browser do what you want. If I want a link in a new window, I'm perfectly capable of doing that myself.

Your site's look and feel is your domain; my browser is my domain.
posted by Mikey-San at 6:39 PM on July 21, 2007


beaucoupkevin & ph00dz - I tried both of your techniques that you kindly suggested, but both times Blogger throws up an error when I try to preview.

Mikey-San - I don't really see how your response answers my question.
posted by Rabulah at 8:48 AM on July 22, 2007


I agree with Mikey-san. It's about web browsing philosophy, but it's important. Whether a link opens in a new window should be up to the person viewing the page, not the page's author.

If I want a link to open in a new window, I'll use the contextual menu (I think it's a right-click if you're a windoid). If you force my browser to open a new window when I click a link, I can pretty much guarantee that your site will disappear from my bookmarks forever.

Are you afraid that people won't hit the back button after you've vectored them to some new site? The answer is to make your content compelling enough that they will come back or choose to use the contextual menu (as I do) to preserve the originating page.
posted by metabeing at 9:41 AM on July 22, 2007


I didn't ask "Is it a good idea for $this to happen?". I asked how I could make it happen. If I had wanted to discuss whether it was a good idea or not, that would have been my question. Since it wasn't, I'd appreciate it if those responding actually read the original question, and responded to it, rather than the moral issues surrounding it.
posted by Rabulah at 2:20 AM on July 23, 2007


Mikey-San - I don't really see how your response answers my question.

No offense, but I don't really see how your question is the best idea in the first place.

Sometimes the real solutions are to the questions we should've asked, but didn't. In your case, the best answer is not to do what you're attempting to implement.
posted by Mikey-San at 6:58 PM on July 25, 2007


No offense, but I don't really see how your question is the best idea in the first place.

I didn't ask if it was a good idea. I asked how it was done. Pretty clearly too, I think.

An response that doesn't answer the question is worse than useless.
posted by Rabulah at 2:35 PM on July 26, 2007


« Older Shooting ranges in New Jersey?   |   Sex is making me bleed. Newer »
This thread is closed to new comments.