8 Replies - 3071 Views - Last Post: 10 January 2013 - 08:52 AM

#1 Spider  Icon User is offline

  • Arachnid

Reputation: 2
  • View blog
  • Posts: 769
  • Joined: 10-July 02

Javascript Url Variables

Posted 23 October 2002 - 08:32 AM

basically, how do I grab a url variable with javascript and set it as a url?

I've found a script that prints the variable on the page, but that isn't a lot of help to me, and I'm not too good with js, so my attempts at altering the script failed dismally :(
Is This A Good Question/Topic? 0
  • +

Replies To: Javascript Url Variables

#2 Spider  Icon User is offline

  • Arachnid

Reputation: 2
  • View blog
  • Posts: 769
  • Joined: 10-July 02

Re: Javascript Url Variables

Posted 25 October 2002 - 09:25 AM

anyone?
Was This Post Helpful? 0
  • +
  • -

#3 geohhot  Icon User is offline

  • New D.I.C Head

Reputation: 8
  • View blog
  • Posts: 33
  • Joined: 22-December 12

Re: Javascript Url Variables

Posted 10 January 2013 - 06:11 AM

I am here!
I have got an idea about solution. Like if you have a div and want to turn all it's URLs into links( <a href="blalbha"> ), than just get text of that div in string, and use .split method. In that case you will get array of string, and use .forEach to check if there is any URLs. For that, just use this
function ValidURL(str) {
  var pattern = new RegExp('^(https?:\/\/)?'+ // protocol
    '((([a-z\d]([a-z\d-]*[a-z\d])*)\.)+[a-z]{2,}|'+ // domain name
    '((\d{1,3}\.){3}\d{1,3}))'+ // OR ip (v4) address
    '(\:\d+)?(\/[-a-z\d%_.~+]*)*'+ // port and path
    '(\?[;&a-z\d%_.~+=-]*)?'+ // query string
    '(\#[-a-z\d_]*)?$','i'); // fragment locater
  if(!pattern.test(str)) {
    alert("Please enter a valid URL.");
    return false;
  } else {
    return true;
  }
}


Actually found this post here. And if in any string it returns true, just turn that string to URL. I think you can make changes in same array, after that just join that string using .join(" ")
Was This Post Helpful? 0
  • +
  • -

#4 Anthonidas  Icon User is offline

  • D.I.C Head

Reputation: 31
  • View blog
  • Posts: 223
  • Joined: 25-April 11

Re: Javascript Url Variables

Posted 10 January 2013 - 07:40 AM

you set a URL with document.location = "yourURL";

but what do you have so far? there is not enough information to understand what you want to do...
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3806
  • View blog
  • Posts: 13,488
  • Joined: 12-December 12

Re: Javascript Url Variables

Posted 10 January 2013 - 08:03 AM

I think Spider may have moved on since he posted the question :whistling: ..in 2002.
Was This Post Helpful? 0
  • +
  • -

#6 Anthonidas  Icon User is offline

  • D.I.C Head

Reputation: 31
  • View blog
  • Posts: 223
  • Joined: 25-April 11

Re: Javascript Url Variables

Posted 10 January 2013 - 08:10 AM

lol right... didn't notice the date of the post :P/>
i was just watching today's new posts so i answered that one... geohot was missleading for me, sorry ;)

This post has been edited by Anthonidas: 10 January 2013 - 08:11 AM

Was This Post Helpful? 0
  • +
  • -

#7 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3806
  • View blog
  • Posts: 13,488
  • Joined: 12-December 12

Re: Javascript Url Variables

Posted 10 January 2013 - 08:26 AM

View PostAnthonidas, on 10 January 2013 - 08:10 AM, said:

lol right... didn't notice the date of the post :P/>/>
i was just watching today's new posts so i answered that one... geohot was missleading for me, sorry ;)/>


I've done this myself before (several times..) :whistling:
Was This Post Helpful? 0
  • +
  • -

#8 geohhot  Icon User is offline

  • New D.I.C Head

Reputation: 8
  • View blog
  • Posts: 33
  • Joined: 22-December 12

Re: Javascript Url Variables

Posted 10 January 2013 - 08:32 AM

Anthonidas why you down voted my post ? Isn't it helpful ?
Actually I think I must get banned for resurrecting dead post.
Was This Post Helpful? 0
  • +
  • -

#9 Anthonidas  Icon User is offline

  • D.I.C Head

Reputation: 31
  • View blog
  • Posts: 223
  • Joined: 25-April 11

Re: Javascript Url Variables

Posted 10 January 2013 - 08:52 AM

View Postgeohhot, on 10 January 2013 - 04:32 PM, said:

Anthonidas why you down voted my post ? Isn't it helpful ?
Actually I think I must get banned for resurrecting dead post.


No it isn't!
Firstly, you answered a question posted 11 years ago, and secondly, your post does not answer the question...

No one mentionned any bans... why should you be banned? Just because --> my personal feeling <-- is, that this post is not useful? Don't worry, you won't.

This post has been edited by Anthonidas: 10 January 2013 - 08:53 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1