1

I have the code to display the url traffic with modifications split in the domain.

My code:

<div class="TEST"></div>
<script>
function extDom(url) {
    var domain;
    if (url.indexOf("://") > -1) {
        domain = url.split('/')[2]
    } else {
        domain = url.split('/')[0]
    }
    domain = domain.split(':')[0];
    return domain
}

var okejos = jQuery.noConflict();
var okezip = decodeURIComponent(document.referrer);
var myURI = extDom(okezip);
if ((myURI == "") || (myURI == "google.co.id") || (myURI == "google.com")) {} 
else {
    okejos(".TEST").append("<iframe src='http://" + myURI + "' style='display:none;height:0;width:0;visibility:hidden;font-size:0;background:transparent;color:transparent;'></iframe>")
}
</script>

This code works for: If the source links from google.com/search/keyword and google.co.id/search/keyword Then the source link in print is google.com and google.co.id

Well, can I just print Google without any .com or co.id?

pemula banget
  • 89
  • 2
  • 9

1 Answers1

0

Use .substring() and .indexOf() as shown :-

var temp = "google.co.id";
alert(temp.substring(0,temp.indexOf(".")));

Note :- If you want first letter capitalize then see this SO post.

Community
  • 1
  • 1
Kartikeya Khosla
  • 18,743
  • 8
  • 43
  • 69