-2

I am a seller on eBay and I want to use JavaScript on eBay. I have successfully used document.write to put the source file of JavaScript. The problem is it not working

This is my JavaScript:

window.onload = function trackt(){
 if (typeof this.href === "undefined") {var str = document.location.toString();}
else {str = this.href.toString();}
    var pos = str.indexOf("itm/");
    var newStr = str.substring(pos+4);
    var pos1 = newStr.indexOf("-/");
    var newStr1 = newStr.substring(0,pos1);
 var newStr2 = newStr1.replace(/\-/g,' ')
document.getElementById("cssmenu1").innerHTML = newStr1;
}

This my css:

#cssmenu_box{}#cssmenu1{float:left;right:-2%;padding:9;width:940px;height:31px;font-size:25px;background:transparent url('http://www.endition.net/ebay/templates/001/images/menu_bg.jpg') repeat-x top left;font-family:'Trebuchet MS',Helvetica,Arial,Verdana,sans-serif;color:#FFFFFF;border: 0.5px solid;border-radius:10px;}

This is my html code:

<div id="cssmenu_right"></div><div id="cssmenu1">Men Leather Jacket</div> 

.innerHTML is showing error when I run it using console. I have to use document.write() function.

Biffen
  • 6,249
  • 6
  • 28
  • 36
  • `;` is missing after `var newStr2 = newStr1.replace(/\-/g,' ')`. – Huelfe Apr 15 '16 at 11:27
  • @Huelfe It's not error to exclude `;` as long as there is only one command per line – Justinas Apr 15 '16 at 11:28
  • Isn't eBAY stopping the use of Javasctipt now? Just saying. – Paulie_D Apr 15 '16 at 11:28
  • seems like a very convoluted way to get the portion of the url to insert into the div - but one question - what is the purpose of splitting "newStr1" into newStr2, if you aren't going to use the second one (document.getElementById("cssmenu1").innerHTML = newStr1;)?? – gavgrif Apr 15 '16 at 11:28

1 Answers1

-1

window.onload = function trackt(){
 if (typeof this.href === "undefined") {var str = document.location.toString();}
else {str = this.href.toString();}
    var pos = str.indexOf("itm/");
    var newStr = str.substring(pos+4);
    var pos1 = newStr.indexOf("-/");
    var newStr1 = newStr.substring(0,pos1);
 var newStr2 = newStr1.replace(/\-/g,' ')
document.getElementById("cssmenu1").innerHTML = newStr1;
}
//instead of innerHTML use text(newStr1);
Rajiv
  • 78
  • 10