0

I am using the following code in my blog, but this script opens the external URL in the native tab itself. I want to redirect it to a new tab altogether.

<script type="text/javascript">
    window.location = "http://externalblog.blogger.com/externalpost";
</script>
esqew
  • 42,425
  • 27
  • 92
  • 132

2 Answers2

0

Try window.open("http://externalblog.blogger.com/externalpost"); This should work.

Vlas Bashynskyi
  • 1,886
  • 2
  • 16
  • 25
  • I tried this but does not work. I use blogger and in one of my posts in the home page I want to direct users to an external link in a new tab. Thank you – user3799020 Jul 02 '14 at 19:52
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. – Yan Sklyarenko Jul 02 '14 at 20:05
  • @YanSklyarenko I disagree. The user did attempt to answer the question. Whether the answer is correct or not is another story, but incorrect answers are not off topic. – Mike Jul 02 '14 at 20:14
  • @Mike, well, in order to make it more an answer than a comment the user should add some explanation why his proposal should work. Otherwise it sounds like a blind guess, which is rather a comment – Yan Sklyarenko Jul 03 '14 at 06:12
  • @YanSklyarenko You've got a point. I generally find code-only answers pretty useless, however considering the question is only one line too and the difference is one word, I wouldn't think it would require much explanation in this case. – Mike Jul 03 '14 at 16:51
0

Use the window.open method to open in a new window / tab

window.open(strUrl, strWindowName[, strWindowFeatures]);

Refer to MDN for details.

Here is an example

var windowObjectReference;
var strWindowFeatures = "menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes";

function openRequestedPopup() {
  windowObjectReference = window.open("http://externalblog.blogger.com/externalpost", "Blogger Window", strWindowFeatures);
}

Call the openRequestedPopup() method on whatever condition you want it to open. Alternately, if you already have the link while rendering the HTML, use the target="_blank" attribute in the anchor tag.

Scorpion-Prince
  • 3,574
  • 3
  • 18
  • 24
  • May you kindly explain with practical examples of all elements in the script with the external link I have provided in my query. Thank you. – user3799020 Jul 02 '14 at 19:55
  • Added the example. Please state your problem clearly, and advise you to do some preliminary research before posting the question on Stack Overflow. – Scorpion-Prince Jul 02 '14 at 21:40