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

Ask A Question

Stats

  • Questions 509k
  • Answers 509k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer To do what you're talking about, first you need to… May 16, 2026 at 4:42 pm
  • Editorial Team
    Editorial Team added an answer This is nested. Don't listen to alert, try console.log instead.… May 16, 2026 at 4:42 pm
  • Editorial Team
    Editorial Team added an answer You can change the URL your file thinks is the… May 16, 2026 at 4:42 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have this code to send data: function insert_new_image() { var ids = [];
How to write this JavaScript code without eval? var typeOfString = eval(typeof + that.modules[modName].varName);
I want to insert a bezier spline into my Canvas by this code <mx:Canvas
What is wrong with this code? <?php class users { var $user_id, $f_name, $l_name,
i have a question in JQuery..I m using $.ajax() in my code (Function 1)
iam using a simple insert script function to pass the values from registration html
UPDATED CODE TO LATEST ITERATION The following function consumes a webservice that returns address
I created a function to take location input, pass it to Google Maps Javascript
Below is my javascript code snippet. Its not running as expected, please help me
Kind of stuck with this thing, that's why need help please. I am using

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.