开发者

Change base href using javascript

开发者 https://www.devze.com 2022-12-09 10:35 出处:网络
Can I change thehref by javascript? I use the following code inbut it doesn\'t work: <base href=\"/\" />

Can I change the href by javascript?

I use the following code in but it doesn't work:

<base href="/" />
<script type="text/javascript"> 
fu开发者_运维技巧nction setbasehref(basehref) { 
 var thebase = document.getElementsByTagName("base"); 
 thebase[0].href = basehref; 
} 
//setbasehref("/");
setbasehref("http://newurl.com");
</script> 


This line:

document.getElementsByTagName("base"); 

Do you have an element of type "base"?

Perhaps you could try grabbing the element by its ID attribute?

 document.getElementById("YourHyperlinksID"); 

Good luck

0

精彩评论

暂无评论...
验证码 换一张
取 消