Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 919557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:33:54+00:00 2026-05-15T18:33:54+00:00

This is my code: function insert(){ var loc_array = document.location.href.split(‘/’); var linkElement = document.getElementById(waBackButton);

  • 0

This is my code:

 function insert(){
  var loc_array = document.location.href.split('/');
  var linkElement = document.getElementById("waBackButton");
  var linkElementLink = document.getElementById("waBackButtonlnk");
  linkElement.innerHTML=loc_array[loc_array.length-2];
  linkElementLink.href = loc_array[loc_array.length];
 }

I want linkElementLink.href to grab everything but the last item in the array. Right now it is broken, and the item before it gets the second-to-last item.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T18:33:55+00:00Added an answer on May 15, 2026 at 6:33 pm

    Use pathname in preference to href to retrieve only the path part of the link. Otherwise you’ll get unexpected results if there is a ?query or #fragment suffix, or the path is / (no parent).

    linkElementLink.href= location.pathname.split('/').slice(0, -1).join('/');
    

    (But then, surely you could just say:)

    linkElementLink.href= '.';
    

    Don’t do this:

    linkElement.innerHTML=loc_array[loc_array.length-2];
    

    Setting HTML from an arbitrary string is dangerous. If the URL you took this text from contains characters that are special in HTML, like < and &, users could inject markup. If you could get <script> in the URL (which you shouldn’t be able to as it’s invalid, but some browser might let you anyway) you’d have cross-site-scripting security holes.

    To set the text of an element, instead of HTML, either use document.createTextNode('string') and append it to the element, or branch code to use innerText (IE) or textContent (other modern browsers).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this JS code: Download.prototype.insert = function(stocks, exchange, cb){ var self = this
In this jquery code: $(document).ready(function(){ $list = $(.channeList li); $list.click(function(){ var $this = $(this);
I have this code: <script type=text/javascript> $(document).ready(function(){ var id = 'i1'; var image =
I have this code : <input type=text id=myText class=input_box_hidden /> $(document).ready(function() { var nomeAzienda=$(#myText);
I have got this code: function init(){ if (typeof window.jQuery !== 'function') { var
I got this code: function zeroPad(num, places) { var zero = places - num.toString().length
Hello I get a weird error in this code: function validateForm(aform) { var s=;
I have this code: _trackit: function(){ for(var key in this.items.sublinks){ switch(key){ case 'shoes': for(var
I have this code to send data: function insert_new_image() { var ids = [];
I have this code which works. $(document).ready(function(){ $('form').live('submit', function(){ // have to do it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.