Need help modifying a Perl script!
I have a Perl Clickgo script that I want modified but don't have the technical experise (yet) to get it done in a timely manner.
The script is called from an HTML drop down form and links the visitor to the page they selected from the drop down.
The problem
===========
The script assumes you're always going to another sepoerate web page so it prefixes the url with "http://". But sometimes I want to use the script to let visitors jump quickly to a point within the same web page (i.e. within the current page).
The change
==========
I want the script to look at the option value being sent and if the value starts with "www" then it can assume it'another web page and insert "http://". But if the value begins with a "#" then it should assume it's a jump to a bookmark within the same/current web page and just go to that bookmark.
If anyone can help I'd appreciate it!
Thank you in advance.
Ken Elliott posted this at 14:49 — 9th November 2000.
They have: 358 posts
Joined: Jun 1999
Jaiem,
take a look at the script, if you know a little bit about perl you will find where it adds the "http://" to it. Just add in if/else statement like this.
if ($url =~ m/www\./) {
#then add the http:// because it is a separate site
} else {
#just go as is
}
If you still can't figure it out, post a text version of the script on a website and surely one of us will make those little additions for you.
Pimpin like a pimp with an electrofied pimpin machine!
Jaiem posted this at 17:27 — 9th November 2000.
They have: 1,191 posts
Joined: Apr 1999
Thanks Ken. I'll try and let you know.
Mark Hensler posted this at 19:08 — 9th November 2000.
He has: 4,048 posts
Joined: Aug 2000
I wouldn't look for 'www' because this works as well:
http://webmaster-forums.com
And there ain't no 'www'
...just look for the # as the first character...
if ($url =~ /^\#/) {
# just go to the bookmark
}
else {
#did they include 'http://'?
if ($url =~ /http:\/\//) {
# do nothing
}
else{
$url = "http://".$url;
}
}
Good Luck
Mark Hensler
If there is no answer on Google, then there is no question.
Jaiem posted this at 03:36 — 15th November 2000.
They have: 1,191 posts
Joined: Apr 1999
OK, think I got the Perl matching part. But ran into an unexpected probelm:
How do you code the Perl to goto the bookmark??
Here's the current page tranfer line:
print ("Location: [url]http://$input{'goto'}\n\n");[/url]
How do I change it to just jump to a bookmark within the current page?
Thanks again.
Jaiem posted this at 04:28 — 15th November 2000.
They have: 1,191 posts
Joined: Apr 1999
I've looked into it more. Don't think this is going to work as I had hoped.
Normally when you goto a bookmark you do so by using "http://www.yourdomain.com#yourbookmark". The jump to the bookmark is really a browser function.
The dilema is that I'm using a CGI script. So there is no page in memory when the script is called. It has to reload the page.
Mark Hensler posted this at 06:39 — 15th November 2000.
He has: 4,048 posts
Joined: Aug 2000
now wait a minute, can't you print a hyperlink in the page that is like ?
why do you want to use the loaction header?
I'm corn-fuzzled...
Jaiem posted this at 14:00 — 15th November 2000.
They have: 1,191 posts
Joined: Apr 1999
My Perl isn't up to where I'd like it to be (yet!) so I was just copying what was already in the script.
The point of my second post is that I don't think using will work either.
Since the HTML document is calling a CGI script it may look like the page is still on the screen. But from the POV of the browser control has been transfered to the CGI script so there is no html doc any more in memory to find the bookmark in.
I could use but that would cause a full reload of the page and take much time. I'm trying to use the clickgo script to jump to the bookmark directly without having to reload the entire page.
The only thing I can think of is to create some Javascript instead and I really don't want to do that.
Any suggestions?
japhy posted this at 14:48 — 15th November 2000.
They have: 161 posts
Joined: Dec 1999
The server has NOTHING to do with URL fragments (the "#anchor" text at the end of a URL). The server does not have the ability to position a file in a browser window at a certain line.
Rather, the browser has EVERYTHING to do with the "#anchor" text -- there is absolutely no server interaction or intervention when you click on a link to jump to another section of the page.
This means that you can use such anchor tags in your program, Jaeim.
And the browser could care less where the document came from. It can't tell an HTML document from a program returning HTML content. It just doesn't know.
Jaiem posted this at 15:15 — 15th November 2000.
They have: 1,191 posts
Joined: Apr 1999
Japhy - I agree and understand.
Let me put it another way:
Suppose you have an HMTL doc with a link to some CGI script. When the user clicks the link the script is run (i.e. a "goto script" is performed). Now suppose the script wants to return the user to a specifc place back in the html doc. The script is in control, not the local html doc. Inorder for the script to return to a specific place in the html it has to use the full url to reload the page (i.e. [url]http://www.somewhere.com/somepage.htm#bookmark).[/url] It can't use just #bookmark.
Try it yourself. Load a page with a bookmark. After it loads type #whatever in the url line. It won't work.
Suzanne posted this at 18:37 — 15th November 2000.
She has: 5,507 posts
Joined: Feb 2000
But if the tag is in the HTML of the document, no matter how it gets there, it works the same.
You might be missing the that the is calling.
Your problem, as you have explained it, doesn't make sense. If the page is being printed with links on it, and those links are for internal targets, and those are valid HTML, it should work. Period.
Please provide more code!
Suzanne
Jaiem posted this at 18:46 — 15th November 2000.
They have: 1,191 posts
Joined: Apr 1999
One more time:
I have an HTML doc that usues a clickgo Perl CGI script via a Form. The form sends a url to the script. The script takes the url, adds http:// and goes to that page. This functionality works fine.
But I want to modify the script (if possible) so that instead of always assuming you're sending it a url it will accept a bookmark instead. In that case instead of trying to goto a new web page it should just jump to the tag in the current HTML doc.
It sounded simple enough. But the problem I think is that jumping to a bookmark (such as with ) is internal to the specific HTML doc. The script is running via link (i.e. not inline with the HTML doc). As such when the script runs there is no page it's associated with. It's just a Perl cgi script running. It doesn't know what page it came from so there's no bookmark tag to be found.
I'll try to put the full script up on a page shortly so you can see.
Suzanne posted this at 23:21 — 15th November 2000.
She has: 5,507 posts
Joined: Feb 2000
Internal anchors are only understood relative to the page.
So if you want to go to www.somesite.com/somepage.html#target, you need to have the full url if no page is loaded (because there is no context for the link). Okay, this much you have straight, right?
So, for the script, what you want to have is two options or variables. One is the url of the page (full) and the other is any internal target. Check to see if there is a target (if target, then print url#target, if no target, print url).
Right?
Suzanne
Jaiem posted this at 02:45 — 16th November 2000.
They have: 1,191 posts
Joined: Apr 1999
Suzanne - Bingo!
That's the problem. When the script is running there is no page relative to the script. So there is no bookmark for the browser to understand.
I don't want to use url#bookmark. That's what I have now and that obviously causes a full reload of the page even if it's a jump to a book mark just a few clicks down. The point of the (hopeful) modification is to speed up going to bookmarks with in the same page.
Mark Hensler posted this at 05:29 — 16th November 2000.
He has: 4,048 posts
Joined: Aug 2000
I think I know what you want, but I need to see an example (URL please) to understand what the form is doing.
I'm guessing that you have a text box. put some url in it and click 'go'. then the CGI prints the http://$url page. Did I get that right?
What you want to do is use a form with a text box. allow users to put a (valid) bookmark in the text box, and click 'go'. Then have the browser internally jump to the ancher tag. Did I get that right?
I wrote this up in a minute or so. I'm not quite sure if it works though, it's too fast to notice, so you'll have to try it with more content on it.
<html>
<script language=javascript>
<!--
function go() {
self.location="#"+place.value
}
//-->
</script>
<body>
<BR>x<BR><BR><BR><BR>
<BR>x<BR><BR><BR><BR>
<BR>x<BR><BR><BR><BR>
<BR>x<BR><BR><BR><BR>
<input type=text name=place>
<input type=button onClick="go()" value="Go">
<BR>x<BR><BR><BR><BR>
<BR>x<BR><BR><BR><BR>
<BR>x<BR><BR><BR><BR>
<BR>x<BR><BR><BR><BR>
<BR>x<BR><BR><BR><BR>
<BR>x<BR><BR><BR><BR>
<BR>x<BR><BR><BR><BR>
<BR>x<BR><BR><BR><BR>
<a name="bottom">
</body>
</html>
Mark Hensler
If there is no answer on Google, then there is no question.
Suzanne posted this at 07:24 — 16th November 2000.
She has: 5,507 posts
Joined: Feb 2000
Going back a few posts, that's because CGI/Perl CANNOT WORK CLIENT SIDE which is what would have to happen for an internal target to work without reloading the document currently in the browser.
CGI/Perl -- SERVER SIDE
JavaScript -- CLIENT SIDE
Server side means the request is sent to the server, and the server returns the new document (MUST refresh the page in the window if it's the same page), whereas client side means the request is sent only to the browser, and can therefore either send a request from there to the server (in the case of a new document) or pop down the page (in the case of an internal target in an existing document).
So you can't do it with Perl because you cannot use SERVER SIDE TECHNOLOGY to affect a change CLIENT SIDE without serving up a new document.
Capiche?
You can have a JavaScript drop-down form that does this, however. Quite easily. But not a Perl form that is parsed through the server. It CANNOT BE DONE.
Suzanne
Jaiem posted this at 13:59 — 16th November 2000.
They have: 1,191 posts
Joined: Apr 1999
That's what I thought you'd say. Was hoping to just canablize the perl script but doesn't seem possible.
Oh well. Thanks for the input everyone. Going to bug them over at the Javascript forum....
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.