Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Community Discussions (All other subjects)
 Some Javascript Help
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

JJenson
Advanced Member

USA
2121 Posts

Posted - 03 October 2007 :  10:08:55  Show Profile  Visit JJenson's Homepage
Ok I have this funtion

function listLink(product)
{
url = document.getElementById(product).value;
window.open(url);
}

This allows me to set a value in a select drop down list to be a url and then it opens a new window to that link.

I need to add a statement to it and I am not sure how. Basically I want it to open up a new window when it is a absolute url. But if I put something like a # sign I want it to just do nothing or refresh the page either one would work. I just don't want it to open a new window right now it opens a new window that is blank.

Thanks

Podge
Support Moderator

Ireland
3776 Posts

Posted - 03 October 2007 :  10:39:08  Show Profile  Send Podge an ICQ Message  Send Podge a Yahoo! Message
You would need a javascript function which takes a url and returns a boolean value whether its a good url or a bad one.

Change your initial javascript to something like
function listLink(product)
{
if (checkUrl(url))
{
url = document.getElementById(product).value;
window.open(url);
}
}


Where checkUrl(url) is you new url checking function.

Podge.

The Hunger Site - Click to donate free food | My Blog | Snitz 3.4.05 AutoInstall (Beta!)

My Mods: CAPTCHA Mod | GateKeeper Mod
Tutorial: Enable subscriptions on your board

Warning: The post above or below may contain nuts.
Go to Top of Page

Podge
Support Moderator

Ireland
3776 Posts

Posted - 03 October 2007 :  10:42:23  Show Profile  Send Podge an ICQ Message  Send Podge a Yahoo! Message
Here's one from here and altered to suit your needs.

function checkUrl(s) {
	var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	return regexp.test(s);
}


None of my code is tested so you may have errors.

Podge.

The Hunger Site - Click to donate free food | My Blog | Snitz 3.4.05 AutoInstall (Beta!)

My Mods: CAPTCHA Mod | GateKeeper Mod
Tutorial: Enable subscriptions on your board

Warning: The post above or below may contain nuts.
Go to Top of Page

JJenson
Advanced Member

USA
2121 Posts

Posted - 03 October 2007 :  10:48:59  Show Profile  Visit JJenson's Homepage
Thanks I am just starting on the javascript side of things so sorry if I missed something here.

This is how I changed my code

function listLink(product)
{
if (checkUrl(url))
{
url = document.getElementById(product).value;
window.open(url);
}
}
function checkUrl(s) {
var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
return regexp.test(s);
}


This brings up an error that says url is not defined. Not sure where to go from here?

Thanks
Go to Top of Page

JJenson
Advanced Member

USA
2121 Posts

Posted - 03 October 2007 :  10:53:42  Show Profile  Visit JJenson's Homepage
ok got it

this is the code that works.


<script language="javascript">
function listLink(product)
{
url = document.getElementById(product).value;
if (checkUrl(url))
{
window.open(url);
}
}
function checkUrl(s) {
var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
return regexp.test(s);
}

</script>


Thanks so much Podge
Go to Top of Page

Podge
Support Moderator

Ireland
3776 Posts

Posted - 03 October 2007 :  11:28:11  Show Profile  Send Podge an ICQ Message  Send Podge a Yahoo! Message
You're welcome.

Podge.

The Hunger Site - Click to donate free food | My Blog | Snitz 3.4.05 AutoInstall (Beta!)

My Mods: CAPTCHA Mod | GateKeeper Mod
Tutorial: Enable subscriptions on your board

Warning: The post above or below may contain nuts.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.24 seconds. Powered By: Snitz Forums 2000 Version 3.4.07