Forum Moderators: open

Message Too Old, No Replies

Javascript to Remove Html Code

         

matthewamzn

4:15 pm on Sep 9, 2006 (gmt 0)

10+ Year Member



Is there a javascript that can remove html code from a webpage? I want to remove the first part of some urls so that only part of it is visible.

Instead of showing this:
http://www.example.com/search?=help

I want to show this:
help

Little_G

4:49 pm on Sep 9, 2006 (gmt 0)

10+ Year Member



Hi,

Can you please clarify what it is you want to do.

Andrew

matthewamzn

7:31 pm on Sep 9, 2006 (gmt 0)

10+ Year Member



What i'm trying to do is get a youtube video to work within a new forum script. I've got the bb code working so that if a user can get the video id from the url, it can play embedded within the forum.

However, everyone seems to accidentally post the entire url (making the video unplayable). I was thinking if there's a way to strip out the first part of the url, the video could still play.

Little_G

8:20 pm on Sep 9, 2006 (gmt 0)

10+ Year Member



Hi,

This example should do what you want:

<script type="text/javascript">
var url = "http://www.youtube.com/watch?v=AAAAAAAAA";
var searchString = "?v=";
alert(url.substring(url.indexOf(searchString)+searchString.length));
</script>

Andrew

bobming

8:37 pm on Sep 9, 2006 (gmt 0)

10+ Year Member



I've just been working on a similar solution to little G and came up with this:


function stripURL(url)
{
if(url.indexOf('=')!= -1)
{
strip_start = url.lastIndexOf('=');
strip_end = url.length;
return url.substring(strip_start, strip_end);
}
else return url;
}

returns everything after the last '=' in the url (if there is one present).

matthewamzn

10:56 pm on Sep 9, 2006 (gmt 0)

10+ Year Member



I took out the last line from your script. Was it there just as an alert?

<script type="text/javascript">
var url = "http://www.youtube.com/watch?v=AAAAAAAAA";
var searchString = "?v=";
</script>

matthewamzn

11:39 pm on Sep 9, 2006 (gmt 0)

10+ Year Member



My last post didn't make much sense. This is what I'm trying to get to work.

I need to get this url:
[youtube.com...]

To change to this:
[youtube.com...]

Using little g's code:
---------------------------------


<head>
<script type="text/javascript">
var url = "http://www.youtube.com/watch?v=AAAAAAAAA";
var searchString = "?v=";
alert(url.substring(url.indexOf(searchString)+searchString.length));
</script>
</head>
<body>
<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/ovJeGPeh43c"></param><embed src="http://www.youtube.com/v/http://www.youtube.com/watch?v=ovJeGPeh43c" type="application/x-shockwave-flash" width="425" height="350"></embed></object>
</body>

---------------------------------
I don't know much javascript, but the above code I have isn't working.

Little_G

12:24 am on Sep 10, 2006 (gmt 0)

10+ Year Member



Hi,

try this:


<body>
<script type="text/javascript">
var url = "http://www.youtube.com/v/http://www.youtube.com/watch?v=ovJeGPeh43c";
var searchString = "?v=";
var out = "<object width=\"425\" height=\"350\"><param name=\"movie\" value=\"http://www.youtube.com/v/";
out += url.substring(url.indexOf(searchString)+searchString.length);
out += "\"></param><embed src=\"http://www.youtube.com/v/";
out += url.substring(url.indexOf(searchString)+searchString.length);
out += "\"type=\"application/x-shockwave-flash\" width=\"425\" height=\"350\"></embed></object>";
document.write(out);
</script>
</body>

Andrew

[edited by: Little_G at 12:30 am (utc) on Sep. 10, 2006]

matthewamzn

4:22 am on Sep 10, 2006 (gmt 0)

10+ Year Member



That works great. Thanks!

matthewamzn

8:09 pm on Sep 10, 2006 (gmt 0)

10+ Year Member



For some reason, in internet explorer 7, URL tags are sometimes being added automatically. Is there a way to identify whether or not they were added (and to strip them out if they were)?

This is an example of the problem that is happening:

<body> 
<script type="text/javascript">
var url = "http://www.youtube.com/v/[url ]http://www.youtube.com/watch?v=ovJeGPeh43c[ /url]";
var searchString = "?v=";
var out = "<object width=\"425\" height=\"350\"><param name=\"movie\" value=\"http://www.youtube.com/v/";
out += url.substring(url.indexOf(searchString)+searchString.length);
out += "\"></param><embed src=\"http://www.youtube.com/v/";
out += url.substring(url.indexOf(searchString)+searchString.length);
out += "\"type=\"application/x-shockwave-flash\" width=\"425\" height=\"350\"></embed></object>";
document.write(out);
</script>
</body>

Little_G

8:57 pm on Sep 10, 2006 (gmt 0)

10+ Year Member



Hi,

That url tag problem must be caused by another script you are using, it shouldn't have anthing to do with Internet Explorer 7 specifically.

Andrew

matthewamzn

9:06 pm on Sep 10, 2006 (gmt 0)

10+ Year Member



It seems to happen in my wysiwyg editor. If a url is pasted in it, it gets automatically wrapped in url tags. Seems to only happen in internet explorer 7.

Little_G

1:12 pm on Sep 11, 2006 (gmt 0)

10+ Year Member



Hi,

You might want to start a new tread about that.

Andrew