Add html to <head> using jQuery

My situation is that I have a button and some links on the page. When the user clicks the button, he tries to add the <base> to <head>

 function avoidRediect(){ $('head').append('<base target="_blank" />'); } 

But the page does not take effect (means that the link is still open in the same window). Am I right? Thanks in advance.

0
source share
2 answers

This should actually work.

Example: http://www.jsfiddle.net/YjC6y/37/

If you delete the Javascript line, it will open in the same frame.

Which browser do you use there?

0
source

You can get the head-tag with getElementsByTagName ... for example:

 var headID = document.getElementsByTagName("head")[0]; $(headID).append('<base target="_blank" />'); 

In quick validation, this worked, at least on chrome and firefox 3.6.

0
source

Source: https://habr.com/ru/post/1343029/


All Articles