开发者

Script to change website text based on domain name

Is there an easy way to change a line of html text on a web page(e.g. a welcome message), based on the Domain Name?

e.g.

  • user visits via mydomain.com - text welcome message = 开发者_运维知识库"Welcome to our USA website"
  • user visits via mydomain.co.uk - text welcome message = "Welcome to our UK website"

Is there a script to change the text dynamically based on which domin name is accessed?

Thank you


if( $_SERVER[ 'HTTP_HOST' ] == 'mydomain.com' ) {
    $text = "Welcome to our USA website";
} elseif( $_SERVER[ 'HTTP_HOST' ] == 'mydomain.co.uk' ) {
    $text = "Welcome to our UK website";
}


This is how you would do it in Javascript

var url = window.location.host;
if (url == "stackoverflow.com"){
  // Make this visible
  document.getElementById("one").style.display = "block";
  // Make this invisible
  document.getElementById("two").style.display = "none";
} else {
  // Make this invisible
  document.getElementById("one").style.display = "none";
  // Make this visible
  document.getElementById("two").style.display = "block"; 
}
<div id="one">ONE</div>
<div id="two">TWO</div>

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜