2

I have this "parameter" %%name%% working, this %%name%% will be replaced with the user name on my URL.

My URL will be:

http://www.inversa.com/XV-MI-LJI-GLP-AIN-20181101-ADEA-PSNL-PR3-X/Marcus

I need one script that copy that "parameter" after the last "/", and paste on my HTML code where I want.

Example: Hello, Marcus.

Victor
  • 53
  • 1
  • 6
  • 2
    You can read the value from the URL using `window.location.href.split('/').pop()`, ***however*** be very careful with this in terms of security. You're making it very easy for someone to XSS your site. – Rory McCrossan Nov 01 '18 at 15:49
  • Also what do you mean hide that string in the url? If that string isn't in the url, that's going to send the user to a different page – Taplar Nov 01 '18 at 15:52
  • this may help -> https://stackoverflow.com/questions/12832317/history-replacestate-example?answertab=votes#tab-top – treyBake Nov 01 '18 at 16:01
  • Can someone send me the script? I'm new on javascript – Victor Nov 01 '18 at 16:39
  • We don't send or provide free scripts on request, we are here to assist genuine efforts. – Andy G Nov 01 '18 at 16:41

2 Answers2

0

If the URL length will be ALWAYS the same (ie after the 66 character it will display the value you want), you can easily achieve that with slice(). Working example:

var str = "http://www.inversa.com/XV-MI-LJI-GLP-AIN-20181101-ADEA-PSNL-PR3-X/Marcus"; 
var res = str.slice(66);
console.log("Hello," + res);

Hope that helps!

Read more about JavaScript methods regarding tto strings here https://developer.mozilla.org/cs/docs/Web/JavaScript/Reference/Global_Objects/String

Good luck!

Note: in order to get the URL replace it with that line:

var str = window.location.href;

This will be good for your particular use case, but i think you should get that name from other source...

A. Meshu
  • 4,053
  • 2
  • 20
  • 34
0

you can try this code:

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title> test</title>
      <script type="text/javascript">
      document.addEventListener("DOMContentLoaded", function(event) {
        var url="http://www.mysubscribers.com/XX-XX-20181101-XX-XX/Marcus";
      var name=url.split("/").pop(-1);
      document.getElementById('myH1').innerHTML=name;//put into h1 the name
      
    });

    </script>
    </head>
    <body>
    <h1 id="myH1"></h1>
    </body>
    </html>
Ferdinando
  • 964
  • 1
  • 12
  • 23