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

  • Home
  • SEARCH
  • 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 6733605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:47:21+00:00 2026-05-26T10:47:21+00:00

The javascript below extracts www.google.com from http://mysite.com?url=www.google.com and writes it as an <a> href

  • 0

The javascript below extracts www.google.com from http://mysite.com?url=www.google.com
and writes it as an <a> href link

<script> 
var urll = (window.location.search.match(/[?&;]url=([^&;]+)/) || [])[1]; 
document.write('<a href="http://'+urll+'">url</a>'); 
</script>

The problem with it is that when it extracts the url the <a> href value it becomes http://mysite.com/www.google.com so the if should state if the original url http://mysite.com?url=www.google.com doesn’t have http:// infront of ?url= then add it after the href value to form <a href="http://www.google.com">url</a>

In a comment for a previous question someone gave me this

if (link.substr(0, 7) !== 'http://') { link = 'http://' + link; }

but I really don’t have a clue on how to implement it because I have never used an if in javascript.

  • 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-26T10:47:22+00:00Added an answer on May 26, 2026 at 10:47 am

    Apart from anything else you’re making yourself suspectible to XSS attacks:

    Assume for a moment that the url parameter (which an external site can easily spoof by providing a link to your site) contains the string "><b>BOLD!</b><div class=". Suddenly your page would display some bold text, even ‘though you never used a <b> tag in your site. And that’s the most harmless example possible, because the attacker can equally well introduce arbitrary JavaScript into your page (including JS that steals the users cookie!).

    Moral of the story: never blindly trust user input, and don’t simply convert it to HTML.

    To avoid these kinds of attacks (SQL Injection is a very similar attack against server-side code that builds SQL statements) do these two things:

    1. validate the input to ensure that it’s exactly what you expect and don’t accept it if it doesn’t. In your case that would mean that you’d want to make sure that the url parameter actually represents a valid URL.
    2. Use user data only in “safe” ways that don’t introduce the possibility of “re-interpretation” of the input. In your case it means that you must not build your HTML using string concatenation like this. Intead use document.createElement() to create your a element, set its href attribute to the desired value (sanitized as stated above) and then add the newly created a element in your DOM at the appropriate position.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the link below: <a href='@Url.Action(MyAction,MyController, new SearchCriteriaAffaire { Page=3, PageSize=5 }, null)'>Test1</a>
Yesterday I moved CultureRater.com across to XHTML 1.0 Transitional and while the javascript below
Consider the JavaScript code below, inspired from the YUI documentation on YAHOO.lang.extend . In
ok so i collect the variable below through javascript. var frameState = $(this).attr('id'); I
I am using the javascript below to send information from one website to another,
I am able to display my tweets in my website using the JavaScript below.
What does the below JavaScript mean? Why is the function embedded inside ()? (function()
I have this javascript code below that uses jquery, it is suppoed to be
How would I achieve the pseudo-code below in JavaScript? I want to include the
I am creating a chunk of HTML/JavaScript with the below code: $result = mysql_query(SELECT

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.