2
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by hyper_boom
0

I'm not very good at regex so I won't attempt to answer with that but you can use simple string operations to achieve this. You could first split the location by "//" and then split the string again by /.

var loc = "http://development/B1888FG65789examp...78685685847437"; /* you would use document.location */
loc = loc.split("//");
var protocol = loc[0];
loc = loc[1];
var finalDisplay = protocol + "//" + loc.split("/")[0] + "/";

It's a bit messy but does what you want.

0

Thank you for this Scappedcola, I cant get it to work but I am guessing I am doing something wrong.

I have inserted the code in like this just above the previous code:

<script language="javascript">
	var loc = "document.location";
	loc = loc.split("//");
	var protocol = loc[0];
	loc = loc[1];
	var finalDisplay = protocol + "//" + loc.split("/")[0] + "/";
</script>

What am I doing wrong?

0

Don't put document.location in quotes. What you are assigning loc is a string containing the words document.location. Instead do:

var loc = document.location.toString();

Edited by mike_2000_17: Fixed formatting

0

Thank you for the quick reply Scappedcola, it is not working as of yet.

The code at the moment looks like this:

<script language="javascript">
	var loc = document.location.toString();
	loc = loc.split("//");
	var protocol = loc[0];
	loc = loc[1];
	var finalDisplay = protocol + "//" + loc.split("/")[0] + "/";
</script>

<div id="footer">You are using an <b><script language="javascript">

document.writeln(document.location);

</script> </b>version of this application </div>
0
div id="footer">You are using an <b><script language="javascript">
 
document.writeln(document.location);
 
</script> </b>version of this application </div>

In the above piece are you trying to display the entire URL or the shortened version we create at finalDisplay? If you want the shortened URL to display you need to

document.writeLn(finalDisplay);

Or you will only get the current full URL.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.