473,395 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Choose code to run based on incoming URL

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
14 2550
"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
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
"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
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
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
"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
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
"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
"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
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
"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
"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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: | last post by:
Is it possible to construct a CDO.To statement based on the value of an incoming form drop down list which contains any word such as "ChangeStatus:" How would I construct the IF statement to...
6
by: Penny | last post by:
Hi all, I've built a simple search <Form> on a web page that is intended to allow the user to search a record store database. There is a drop down box where the user can choose either 'Artist'...
16
by: Robert Zurer | last post by:
Can anyone suggest the best book or part of a book on this subject. I'm looking for an in-depth treatment with examples in C# TIA Robert Zurer robert@zurer.com
12
by: anna | last post by:
Map, generate, and maintain 50% of your .NET application code, namely your business and data objects. Use these objects in ASP.NET, Windows Forms, console or services applications. Business and...
1
by: relisoft | last post by:
SEATTLE, Washington. - July 12, 2006: Reliable Software® announces the upcoming release of Code Co-op® version 5.0. Code Co-op is an affordable peer-to-peer version control system for distributed...
11
by: Genalube | last post by:
I am new to access, so I figure this is an easy question to answer. I just can't find it on my own. Background: Two tables with a one to many relationship (irelevantField1 is a place holder,...
5
by: Jens | last post by:
Hello, I have been looking for some C-code which listens on a user-defined port for incoming data traffic. When data is received, the data is written to a file. I found some C-code (server)...
4
by: Morgan Cheng | last post by:
Since ASP.NET 2.0, asynchronous web service client can be implemented with event-based pattern, instead of original BeginXXX/EndXXX pattern. However, I didn't find any material about event-based...
1
by: gozlemci | last post by:
Hi everybody; During my coding, I have encountered a problem.I appreciate if anybody answer it. Here is the simplified code: //Header5.h #pragma once #include <string> using namespace std;
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.