By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,506 Members | 1,228 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,506 IT Pros & Developers. It's quick & easy.

Choose code to run based on incoming URL

P: n/a
Can I use a bookmark to selectively choose the code to be run?

For example. Suppose we have the following in an HTML file:

<html>

<head>

<script language="JavaScript"><!--

location.href = 'HKlinks.html#B'

//--></script>

<noscript>

<meta http-equiv="Refresh" content="3;url=HowardKaikowServices.html">

</noscript>

</head>

</html>

And hklinks.html has:

<html>

<head>

<a name="A"><script language="JavaScript"><!--

location.href = 'HowardKaikow.html'

//--></script></a>

<a name="B"><script language="JavaScript"><!--

location.href = HowardKaikowServices.html'

//--></script></a>

<noscript>

<meta http-equiv="Refresh" content="3;url=index.html">

</noscript>

</head>

</html>

I want to choose which javascript to run based on the incoming link.

I tried onload.target to choose, but I think I screwed up the sintax.
--
http://www.standards.com/; See Howard Kaikow's web site.
Jul 23 '05 #1
Share this Question
Share on Google+
14 Replies


P: n/a
"Howard Kaikow" <ka****@standards.com> wrote in message
news:ck**********@pyrite.mv.net...
Can I use a bookmark to selectively choose the code to be run?

For example. Suppose we have the following in an HTML file:

<html>

<head>

<script language="JavaScript"><!--

location.href = 'HKlinks.html#B'

//--></script>

<noscript>

<meta http-equiv="Refresh" content="3;url=HowardKaikowServices.html">

</noscript>

</head>

</html>

And hklinks.html has:

<html>

<head>

<a name="A"><script language="JavaScript"><!--

location.href = 'HowardKaikow.html'

//--></script></a>

<a name="B"><script language="JavaScript"><!--

location.href = HowardKaikowServices.html'

//--></script></a>

<noscript>

<meta http-equiv="Refresh" content="3;url=index.html">

</noscript>

</head>

</html>

I want to choose which javascript to run based on the incoming link.

I tried onload.target to choose, but I think I screwed up the sintax.
--
http://www.standards.com/; See Howard Kaikow's web site.


How about the following instead?

<html>
<head>
<script type="text/javascript">
location.href = "HKlinks.html?B";
</script>
<noscript>
<meta http-equiv="Refresh" content="3;url=HowardKaikowServices.html">
</noscript>
</head>
</html>
<html>
<head>
<script type="text/javascript">
var loc = location.search;
if (loc == "?A") location.href = "HowardKaikow.html";
if (loc == "?B") location.href = "HowardKaikowServices.html";
</script>
<noscript>
<meta http-equiv="Refresh" content="3;url=index.html">
</noscript>
</head>
</html>
Jul 23 '05 #2

P: n/a
On Thu, 07 Oct 2004 11:50:34 GMT, McKirahan <Ne**@McKirahan.com> wrote:

[snip]
I want to choose which javascript to run based on the incoming link.

[snip]
How about the following instead?


Since we're only talking about redirection, why not do it the proper way.
With the server.

[snip]

Mike
Please trim quotes!

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #3

P: n/a
"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:opsfh00z0bx13kvk@atlantis...
On Thu, 07 Oct 2004 11:50:34 GMT, McKirahan <Ne**@McKirahan.com> wrote:

[snip]
I want to choose which javascript to run based on the incoming link.

[snip]
How about the following instead?


Since we're only talking about redirection, why not do it the proper way.
With the server.


Because my ISP limits what we can do and even then discourages server side
stuff.

I could use a custom 404 file, but I want to try javascript first.
[snip]

Mike
Please trim quotes!

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.

Jul 23 '05 #4

P: n/a
Thanx, I'll give it a try.

--
http://www.standards.com/; See Howard Kaikow's web site.
"McKirahan" <Ne**@McKirahan.com> wrote in message
news:e4a9d.204833$D%.55378@attbi_s51...
"Howard Kaikow" <ka****@standards.com> wrote in message
news:ck**********@pyrite.mv.net...
Can I use a bookmark to selectively choose the code to be run?

For example. Suppose we have the following in an HTML file:

<html>

<head>

<script language="JavaScript"><!--

location.href = 'HKlinks.html#B'

//--></script>

<noscript>

<meta http-equiv="Refresh" content="3;url=HowardKaikowServices.html">

</noscript>

</head>

</html>

And hklinks.html has:

<html>

<head>

<a name="A"><script language="JavaScript"><!--

location.href = 'HowardKaikow.html'

//--></script></a>

<a name="B"><script language="JavaScript"><!--

location.href = HowardKaikowServices.html'

//--></script></a>

<noscript>

<meta http-equiv="Refresh" content="3;url=index.html">

</noscript>

</head>

</html>

I want to choose which javascript to run based on the incoming link.

I tried onload.target to choose, but I think I screwed up the sintax.
--
http://www.standards.com/; See Howard Kaikow's web site.


How about the following instead?

<html>
<head>
<script type="text/javascript">
location.href = "HKlinks.html?B";
</script>
<noscript>
<meta http-equiv="Refresh" content="3;url=HowardKaikowServices.html">
</noscript>
</head>
</html>
<html>
<head>
<script type="text/javascript">
var loc = location.search;
if (loc == "?A") location.href = "HowardKaikow.html";
if (loc == "?B") location.href = "HowardKaikowServices.html";
</script>
<noscript>
<meta http-equiv="Refresh" content="3;url=index.html">
</noscript>
</head>
</html>

Jul 23 '05 #5

P: n/a
How do I modify the code to handle both ? and # as bookmark delimiters?

For example, in:
<html>
<head>
<p><a href="HKlinks.html?B">B?</a></p>
<p><a href="HKlinks.html?A">A?</a></p>
<p><a href="HKlinks.html#B">B#</a></p>
<p><a href="HKlinks.html#A">A#</a></p>
</head>
</html>

Only the links using ? work.
I commonly see # used instead f ? to separate the bookmark.
What modifications are needed in the following HKlinks.html?
<html>
<head>
<script type="text/javascript"><!--
var loc=location.search;
if(loc=="?A")location.href="HowardKaikow.html";
if(loc=="?B")location.href="HowardKaikowServices.h tml";
//--></script>
<noscript>
<meta http-equiv="Refresh" content="3;url=index.html">
</noscript>
</head>
</html>
Jul 23 '05 #6

P: n/a
"Howard Kaikow" <ka****@standards.com> wrote in message
news:ck**********@pyrite.mv.net...
How do I modify the code to handle both ? and # as bookmark delimiters?

For example, in:
<html>
<head>
<p><a href="HKlinks.html?B">B?</a></p>
<p><a href="HKlinks.html?A">A?</a></p>
<p><a href="HKlinks.html#B">B#</a></p>
<p><a href="HKlinks.html#A">A#</a></p>
</head>
</html>

Only the links using ? work.
I commonly see # used instead f ? to separate the bookmark.
What modifications are needed in the following HKlinks.html?
<html>
<head>
<script type="text/javascript"><!--
var loc=location.search;
if(loc=="?A")location.href="HowardKaikow.html";
if(loc=="?B")location.href="HowardKaikowServices.h tml";
//--></script>
<noscript>
<meta http-equiv="Refresh" content="3;url=index.html">
</noscript>
</head>
</html>


First, you should no longer use "<!--" and "--> within <script> tags.

Second, your <a> tags go inside the <body> not the <head> section.

Thirdly, you have a solution with "?" why try to use "#"?

"#" are used for bookmarks (as you know).

"?" indicates a QueryString which can be interrogated by the called page.
Jul 23 '05 #7

P: n/a
Because when I gove somebody a URL, I usually give it as a web page and,
maybe, a bookmark on that web page, which is also how a lot of folkes are
used to seeing a URL.

I'll have no control whether they use a ? or a #.
Here's what I have in the .js file, but the part about the # is doing what I
need.

<html>
<head>
<script type="text/javascript", SRC ="links.js"></script>
<noscript>
<HR>
<A href="index.html">The URL you used requires the use of JavaScript. If you
wish to use the URL,
please enable support for Javascript in your browser.
You will shortly be taken to http://www.standards.com/index.html, or you can
click here now.</A>
<HR>
<meta http-equiv="Refresh" content="0;url=index.html">
</noscript>
</head>
</html>

The following is currently the link.js file.

var loc=location.search.toUpperCase();
if((loc=="?A")||(loc=="#A")){
location.href="HowardKaikow.html";
}
else if((loc=="?B")||(loc=="#B")){
location.href="HowardKaikowServices.html";
}
else{
alert(location.href + " is not a valid URL.\n" +
"You will be taken to http://www.standards.com/index.html.");
location.href="index.html";
}
--
http://www.standards.com/; See Howard Kaikow's web site.
"McKirahan" <Ne**@McKirahan.com> wrote in message
news:ZZa9d.197917$MQ5.6432@attbi_s52...
"Howard Kaikow" <ka****@standards.com> wrote in message
news:ck**********@pyrite.mv.net...
How do I modify the code to handle both ? and # as bookmark delimiters?

For example, in:
<html>
<head>
<p><a href="HKlinks.html?B">B?</a></p>
<p><a href="HKlinks.html?A">A?</a></p>
<p><a href="HKlinks.html#B">B#</a></p>
<p><a href="HKlinks.html#A">A#</a></p>
</head>
</html>

Only the links using ? work.
I commonly see # used instead f ? to separate the bookmark.
What modifications are needed in the following HKlinks.html?
<html>
<head>
<script type="text/javascript"><!--
var loc=location.search;
if(loc=="?A")location.href="HowardKaikow.html";
if(loc=="?B")location.href="HowardKaikowServices.h tml";
//--></script>
<noscript>
<meta http-equiv="Refresh" content="3;url=index.html">
</noscript>
</head>
</html>


First, you should no longer use "<!--" and "--> within <script> tags.

Second, your <a> tags go inside the <body> not the <head> section.

Thirdly, you have a solution with "?" why try to use "#"?

"#" are used for bookmarks (as you know).

"?" indicates a QueryString which can be interrogated by the called page.

Jul 23 '05 #8

P: n/a
"Howard Kaikow" <ka****@standards.com> wrote in message
news:ck**********@pyrite.mv.net...
Here's what I have in the .js file, but the part about the # is doing what I need.
I meant to say "but the part about the # NOT is doing what I need".


<html>
<head>
<script type="text/javascript", SRC ="links.js"></script>
<noscript>
<HR>
<A href="index.html">The URL you used requires the use of JavaScript. If you wish to use the URL,
please enable support for Javascript in your browser.
You will shortly be taken to http://www.standards.com/index.html, or you can click here now.</A>
<HR>
<meta http-equiv="Refresh" content="0;url=index.html">
</noscript>
</head>
</html>

The following is currently the link.js file.

var loc=location.search.toUpperCase();
if((loc=="?A")||(loc=="#A")){
location.href="HowardKaikow.html";
}
else if((loc=="?B")||(loc=="#B")){
location.href="HowardKaikowServices.html";
}
else{
alert(location.href + " is not a valid URL.\n" +
"You will be taken to http://www.standards.com/index.html.");
location.href="index.html";
}
--
http://www.standards.com/; See Howard Kaikow's web site.
"McKirahan" <Ne**@McKirahan.com> wrote in message
news:ZZa9d.197917$MQ5.6432@attbi_s52...
"Howard Kaikow" <ka****@standards.com> wrote in message
news:ck**********@pyrite.mv.net...
How do I modify the code to handle both ? and # as bookmark delimiters?
For example, in:
<html>
<head>
<p><a href="HKlinks.html?B">B?</a></p>
<p><a href="HKlinks.html?A">A?</a></p>
<p><a href="HKlinks.html#B">B#</a></p>
<p><a href="HKlinks.html#A">A#</a></p>
</head>
</html>

Only the links using ? work.
I commonly see # used instead f ? to separate the bookmark.
What modifications are needed in the following HKlinks.html?
<html>
<head>
<script type="text/javascript"><!--
var loc=location.search;
if(loc=="?A")location.href="HowardKaikow.html";
if(loc=="?B")location.href="HowardKaikowServices.h tml";
//--></script>
<noscript>
<meta http-equiv="Refresh" content="3;url=index.html">
</noscript>
</head>
</html>


First, you should no longer use "<!--" and "--> within <script> tags.

Second, your <a> tags go inside the <body> not the <head> section.

Thirdly, you have a solution with "?" why try to use "#"?

"#" are used for bookmarks (as you know).

"?" indicates a QueryString which can be interrogated by the called page.


Jul 23 '05 #9

P: n/a
"Howard Kaikow" <ka****@standards.com> wrote in message
news:ck**********@pyrite.mv.net...
Because when I gove somebody a URL, I usually give it as a web page and,
maybe, a bookmark on that web page, which is also how a lot of folkes are
used to seeing a URL.

I'll have no control whether they use a ? or a #.
Here's what I have in the .js file, but the part about the # is doing what I need.

<html>
<head>
<script type="text/javascript", SRC ="links.js"></script>
<noscript>
<HR>
<A href="index.html">The URL you used requires the use of JavaScript. If you wish to use the URL,
please enable support for Javascript in your browser.
You will shortly be taken to http://www.standards.com/index.html, or you can click here now.</A>
<HR>
<meta http-equiv="Refresh" content="0;url=index.html">
</noscript>
</head>
</html>

The following is currently the link.js file.

var loc=location.search.toUpperCase();
if((loc=="?A")||(loc=="#A")){
location.href="HowardKaikow.html";
}
else if((loc=="?B")||(loc=="#B")){
location.href="HowardKaikowServices.html";
}
else{
alert(location.href + " is not a valid URL.\n" +
"You will be taken to http://www.standards.com/index.html.");
location.href="index.html";
}


First, you can change
if((loc=="?A")||(loc=="#A")){
to
if(loc=="?A"||loc=="#A"){
if you want.

Second, what do you mean that you "... have no control whether they use a ?
or a #" after you state "... when I gove [sic] somebody a URL". If you give
them a URL it has what ever suffix you include; such as "?A".

Thirdly, it still isn't clear what your really trying to accomplish (big
picture).

It isn't clear why you need to use "#"; is it that you want to jump "into" a
page and not just "to" a page?

Jul 23 '05 #10

P: n/a
I figured out how to handle both ? and #.

I also stumbled upon an easier way get help.
By putting the code in a .js file, I can right click and open in VS .NET
..2003, which gives me the JScript help, etc.
Jul 23 '05 #11

P: n/a
"McKirahan" <Ne**@McKirahan.com> wrote in message
news:fai9d.218509$3l3.31200@attbi_s03...
Second, what do you mean that you "... have no control whether they use a ? or a #" after you state "... when I gove [sic] somebody a URL". If you give them a URL it has what ever suffix you include; such as "?A".
Yes, but there's no reason to not also accept "#A".
I figured out how to do it, see below.
Thirdly, it still isn't clear what your really trying to accomplish (big
picture).
I have a very narrow scope in mind.

I have a web site that has a number of pages I often reference in
newsgroup/web forum postings.
For example, a popular one is
http://www.standards.com/OhMyWord/WordVBABooks.htm, another recent one has
been
http://www.standards.com/OhMyWord/VB...teToolbar.html.

To make it easier for me to remember URLs to give to others and to
facilitate changing the structure of the web site, I decided that a "links"
page would be the right way to go. Server side links would be better, but I
do not yet know how to do that. Should not be difficult to make a custom 404
page, but I do not yet know how. I won't learn PHP just for this purpose.

I would always give URLs to the links page and the link would then be
redirected to the real page, so the above URLs would become, say:

http://www.standards.com/links.html#WordVBABooks and
http://www.standards.com/links.html#...oDeleteToolbar

Those URLs would be much easier to remember.

Of course, those URLs would only work if the user had Javascript enabled.
Otherwise, I will redirect to http://www.standards.com/.

The hard coded URL could still be used, but I won't guarantee those would
not change.
It isn't clear why you need to use "#"; is it that you want to jump "into" a page and not just "to" a page?


All the URLs will be pointing to an anchor in the same page, each of which
will be redirected to the real URL.
If both ? and # work, then I see no reason why my script should not handle
both.

function CompareBookmarks(bmkTarget)
{ var temp = bmkTarget.toLowerCase();
return (locSearch=="?" + temp)||(locHash=="#" + temp);
}
var locHash=location.hash.toLowerCase();
var locSearch=location.search.toLowerCase();
if(CompareBookmarks("HowardKaikow")){
location.href="HowardKaikow.html";
}
else if(CompareBookmarks("HowardKaikowServices")){
location.href="HowardKaikowServices.html";
}
else if(CompareBookmarks("SortPerformanceComparison")){
location.href="Sorting/SortPerformanceComparison-Description.html";
}
else if(CompareBookmarks("ThisandThat")){
location.href="index.html#ThisandThat";
}
else if(CompareBookmarks("CopyFileToPrinter")){
location.href="ThisAndThat/CopyFileToPrinter.html";
}
else{
alert(location.href + " is not a valid URL.\n" +
"You will be taken to http://www.standards.com/index.html.");
location.href="index.html";
}
Jul 23 '05 #12

P: n/a
"Howard Kaikow" <ka****@standards.com> wrote in message
news:ck**********@pyrite.mv.net...
I figured out how to handle both ? and #.

I also stumbled upon an easier way get help.
By putting the code in a .js file, I can right click and open in VS .NET
.2003, which gives me the JScript help, etc.

I'm glad that you figured it out...

The reason "#" is handled differently than "?" is because "?" denotes a
QueryString which is returned via location.search.
Jul 23 '05 #13

P: n/a
"McKirahan" <Ne**@McKirahan.com> wrote in message
news:9Jm9d.142129$wV.114066@attbi_s54...
"Howard Kaikow" <ka****@standards.com> wrote in message
news:ck**********@pyrite.mv.net...
I figured out how to handle both ? and #.

I also stumbled upon an easier way get help.
By putting the code in a .js file, I can right click and open in VS .NET
.2003, which gives me the JScript help, etc.

I'm glad that you figured it out...

The reason "#" is handled differently than "?" is because "?" denotes a
QueryString which is returned via location.search.


I saw that.

But I also now see that ? and # are mot interchangeable.
I found one page for which ? works, but # does not.
http://www.standards.com/links.html?...oDeleteToolbar

http://www.standards.com/links.html#...oDeleteToolbar
Jul 23 '05 #14

P: n/a
I solved the back button problem by using the replace method of the location
object.

--
http://www.standards.com/; See Howard Kaikow's web site.
"Howard Kaikow" <ka****@standards.com> wrote in message
news:ck**********@pyrite.mv.net...
Can I use a bookmark to selectively choose the code to be run?

For example. Suppose we have the following in an HTML file:

<html>

<head>

<script language="JavaScript"><!--

location.href = 'HKlinks.html#B'

//--></script>

<noscript>

<meta http-equiv="Refresh" content="3;url=HowardKaikowServices.html">

</noscript>

</head>

</html>

And hklinks.html has:

<html>

<head>

<a name="A"><script language="JavaScript"><!--

location.href = 'HowardKaikow.html'

//--></script></a>

<a name="B"><script language="JavaScript"><!--

location.href = HowardKaikowServices.html'

//--></script></a>

<noscript>

<meta http-equiv="Refresh" content="3;url=index.html">

</noscript>

</head>

</html>

I want to choose which javascript to run based on the incoming link.

I tried onload.target to choose, but I think I screwed up the sintax.
--
http://www.standards.com/; See Howard Kaikow's web site.

Jul 23 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.