Changing href base with javascript

Is it possible to change href to javascript?

I use the following code, but it does not work:

<base href="/" />
<script type="text/javascript"> 
function setbasehref(basehref) { 
 var thebase = document.getElementsByTagName("base"); 
 thebase[0].href = basehref; 
} 
//setbasehref("/");
setbasehref("http://newurl.com");
</script> 
+3
source share
1 answer

This line:

document.getElementsByTagName("base"); 

Do you have an element of type "base"?

Perhaps you could try to capture an element by its ID attribute?

 document.getElementById("YourHyperlinksID"); 

Good luck.

+3
source

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


All Articles