Forum Moderators: open
<script type="text/javascript" src="http://www.urlhere.com/whatever/vote.php?siteid=42"></script>
now. i know i can include javascript like this. BUT i want to get the 42 out of this URL (using javascript) and print it into the document.
how exactly would i do it?
someone said to me document.location.search but didnt tell me how (on another rival forum which i dont really like) so if anyone would be so kind as to show me how... using location.href would be nice :) if that would work :/
i know for a fact you cant use php, because calling the document as a javascript file seems to force it to read the php tags in javascript coming up with all sorts of wierd errors. hehe. anyway, if anyone could help... THANK YOU!
its for this site...
<snip>
and the banner is what the javascript shows, but i want each member site (of my link site) to display a network banner (by choice to add the code) which will have a link with vote.php?siteid=(THERE SITE ID HERE) on the banner.
Thanks again. Luke (horza) Oliff.
[edited by: Woz at 12:49 am (utc) on Nov. 21, 2003]
[edit reason] No URLs Please, TOS#13 [/edit]
// QueryString
// Call function by x = querystring("variable") returns variable=xfunction QueryString(key)
{
var value = null;
for (var i=0;i<QueryString.keys.length;i++)
{
if (QueryString.keys[i]==key)
{
value = QueryString.values[i];
break;
}
}
return value;
}
QueryString.keys = new Array();
QueryString.values = new Array();function QueryString_Parse()
{
var query = window.location.search.substring(1);
var pairs = query.split("&");for (var i=0;i<pairs.length;i++)
{
var pos = pairs[i].indexOf('=');
if (pos >= 0)
{
var argname = pairs[i].substring(0,pos);
var value = pairs[i].substring(pos+1);
QueryString.keys[QueryString.keys.length] = argname;
QueryString.values[QueryString.values.length] = value;
}
}
}
QueryString_Parse();
BTW you arent allowed to post links to personal sites. Welcome to webmasterworld
and thanks for the warm welcome ;)
so all i do is type
QueryString("siteid") and it will take the siteid from the URL and write it into the script?
[edit, i am a complete n00b with javascript]
I'm have a few issues with a similar script.
I am able to parse the URL, then write the value to a cookie, however with the script I have when returning to [widget.com...] it overwrite the value with a null value.
I guess I would need to have the script first see if there is a value in the cookie and then if not take the value from the URL.
I am new to JavaScript (my first day) and am getting a little over my neck. Any help would be appreciated, here is the script I have so far:
function QueryString(key)
{
var value = null;
for (var i=0;i<QueryString.keys.length;i++)
{
if (QueryString.keys[i]==key)
{
value = QueryString.values[i];
break;
}
}
return value;
}
QueryString.keys = new Array();
QueryString.values = new Array();
function QueryString_Parse()
{
var query = window.location.search.substring(1);
var pairs = query.split("&");
for (var i=0;i<pairs.length;i++)
{
var pos = pairs[i].indexOf('=');
if (pos >= 0)
{
var argname = pairs[i].substring(0,pos);
var value = pairs[i].substring(pos+1);
QueryString.keys[QueryString.keys.length] = argname;
QueryString.values[QueryString.values.length] = value;
}
}
}
QueryString_Parse();
var expDays = 90;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
document.cookie = "referrer_cookie=" + escape(QueryString("referrer_id")) + "; expires=" + exp.toGMTString() + "; path=/" + "; domain=.WIDGET.COM";
:D thanks so much.
if (document.cookie && document.cookie.indexOf("referrer_cookie=") > -1)
{
var refer = document.cookie;
}
else{
function QueryString(key)
{
var value = ("");
for (var i=0;i<QueryString.keys.length;i++)
{
if (QueryString.keys[i]==key)
{
value = QueryString.values[i];
break;
}
}
return value;
}
QueryString.keys = new Array();
QueryString.values = new Array();
function QueryString_Parse()
{
var query = window.location.search.substring(1);
var pairs = query.split("&");
for (var i=0;i<pairs.length;i++)
{
var pos = pairs[i].indexOf('=');
if (pos >= 0)
{
var argname = pairs[i].substring(0,pos);
var value = pairs[i].substring(pos+1);
QueryString.keys[QueryString.keys.length] = argname;
QueryString.values[QueryString.values.length] = value;
}
}
}
QueryString_Parse();
var expDays = 90;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
document.cookie = "referrer_cookie=" + escape(QueryString("referrer_id")) + "; expires=" + exp.toGMTString() + "; path=/" + "; domain=.WIDGET.COM";
}
but how to i document.write it? its got me confused :(
sorry im used to working with php so this javascript is really confusing me
document.write('<a href=\"http://www.gamerforums.org/linksite/vote.php?siteID=\" target=\"_blank\">Vote for this site</a>'); how would i edit this to do it? :(
can you just edit this for me.. cuz with the code you gave me, its stopped it from even displaying.
function QueryString(key)
{
var value = null;
for (var i=0;i<QueryString.keys.length;i++)
{
if (QueryString.keys[i]==key)
{
value = QueryString.values[i];
break;
}
}
return value;
}
QueryString.keys = new Array();
QueryString.values = new Array();
function QueryString_Parse()
{
var query = window.location.search.substring(1);
var pairs = query.split("&");
for (var i=0;i<pairs.length;i++)
{
var pos = pairs[i].indexOf('=');
if (pos >= 0)
{
var argname = pairs[i].substring(0,pos);
var value = pairs[i].substring(pos+1);
QueryString.keys[QueryString.keys.length] = argname;
QueryString.values[QueryString.values.length] = value;
}
}
}
QueryString_Parse();var x;
x = querystring("siteid");
document.write('<div align=\"left\" style=\"position: absolute\; left: 0\; top: 0\; width: 500\; z-index:1\; height:10\">');
document.write('<table width=\"500\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" height=\"25\" style=\"border-collapse: collapse\" bordercolor=\"#111111\">');
document.write(' <tr>');
document.write(' <td valign=\"top\" height=\"25\" width=\"148\">');
document.write(' <a href=\"http://www.gamerforums.org/linksite/index.php');
document.write(' \" target=\"_blank\"><img border=\"0\" src=\"http://www.gamerforums.org/linksite/network/banner_logo_top.gif\" width=\"148\" height=\"25\"></a></td>');
document.write(' <td align=\"center\" height=\"25\" width=\"329\" background=\"http://www.gamerforums.org/linksite/network/banner_bg.gif\"><font face=\"verdana\" size=\"1\"><a href=\"http://www.gamerforums.org/linksite/vote.php?siteID=\" target=\"_blank\">Vote for this site</a></font>');
document.write(' </td>');
document.write(' <td height=\"25\" width=\"25\">');
document.write(' <img border=\"0\" src=\"http://www.gamerforums.org/linksite/network/banner_corner.gif\" width=\"25\" height=\"25\"></td>');
document.write(' </tr>');
document.write(' <tr>');
document.write(' <td width=\"500\" colspan=\"3\">');
document.write(' <img border=\"0\" src=\"http://www.gamerforums.org/linksite/network/banner_logo_bottom.gif\" width=\"148\" height=\"22\"></td>');
document.write(' </tr>');
document.write('</table>');
document.write('</div>');
:((