Google Answers Logo
View Question
 
Q: how to pass an argument to html doc ( Answered 5 out of 5 stars,   0 Comments )
Question  
Subject: how to pass an argument to html doc
Category: Computers > Internet
Asked by: julietott-ga
List Price: $25.00
Posted: 21 Feb 2003 14:27 PST
Expires: 23 Mar 2003 14:27 PST
Question ID: 165387
I have a html page that automatically logs on to a document
repository. I need to pass to the html the url of the document to be
viewed. I can edit the html and set the document to be viewed, but I
need it to dynamically open any document that I call the html page
with.
Currently the shortcut property is set to just the full path to the
html document. And the html document has a line in it which says:
name="p_requested_url" value="url of document to launch is here">
<input type="hidden". (where "url of document to launch is here" is
the actual url of the document)
So my question is how to tell the html page which document I want to
open by passing the value on the command line as an argument, rather
than inputting it or hardcoding it in the html file.

Request for Question Clarification by bio-ga on 21 Feb 2003 17:09 PST
Hi,

Although this can be done on the client side with an HTML page, it is
better to use a server side scripting method for more browser
compatibility. Can you please clarify if you have this HTML page on a
web server (which one, if so), or it is a local file.

Regards
Bio

Request for Question Clarification by j_philipp-ga on 21 Feb 2003 20:12 PST
Julietott,

Added to Bio's questions; in case it's on the server-side, which
scripting languages are supported, and would you prefer a certain one?
Thanks.
Answer  
Subject: Re: how to pass an argument to html doc
Answered By: prophet-ga on 21 Feb 2003 22:52 PST
Rated:5 out of 5 stars
 
Hi Julietott,

You can accomplish what you're trying to do with a little javascript. 
Here is a framework for a document that does what you want:

<html>
<head>
<script language="JavaScript" type="text/javascript">
<!--
var urltext = document.location.href;

if (urltext.indexOf('?') != -1)
	targeturl = urltext.substring((urltext.indexOf('?')+1),urltext.length);
else
	targeturl = document.location.href; // defaults to current page if no
parameter is passed

function init(){
	document.forms[0].p_requested_url.value = targeturl;
}
//-->
</script>
</head>
<body onload="init()">
<form>
<input type="hidden" name="p_requested_url" value=""> 
</form>
</body>
</html>

To integrate this with your page, you just need to copy the javascript
portion into your document's head tags, and insert the onload event
handler into your body tag.  The value in the hidden input field will
be overwritten when the page loads, so it can be left blank or set to
some default page URL.

Now, to call the page.  If this page were located at:
://www.google.com/test.html
then you could pass the URL of your choice through the URL like so:
://www.google.com/test.html?http://www.blahblahblah.com

Basically what happens is that the javascript takes a look at the URL
of the page, and picks up that there is a querystring attached to the
end of it.  It then strips off the querystring and stores it in a
variable.  Then when the page (and more importantly, your form with
the hidden field) loads, the init function is called which sets the
value of your hidden field to the stored value.

Cheers,
Prophet

Request for Answer Clarification by julietott-ga on 22 Feb 2003 03:13 PST
My html page already has an onload event. Can I combine them? I am
posting the full html below.

<html>
<head>
<script language="JavaScript" type="text/javascript"> 
<!-- 
var urltext = document.location.href; 
 
if (urltext.indexOf('?') != -1) 
 targeturl = urltext.substring((urltext.indexOf('?')+1),urltext.length);
else 
 targeturl = document.location.href; // defaults to current page if no
parameter is passed
 
function init(){ 
 document.forms[0].p_requested_url.value = targeturl; 
} 
//--> 
</script> 
  <title>Example Custom HTML Login</title>
  <base href="http://myserver.com/pls/portal30/">
</head>
<body onload="document.forms[0].submit();>
<body onload="init()">   
<form action="PORTAL30.wwptl_login.login_url" method="post"
 name="LoginForm"> <input type="hidden" name="p_requested_url"
 value=""> <input type="hidden"
 name="p_cancel_url" value="http://myserver.com"> <input type="hidden"
 name="ssousername" value="myuser"> <input type="hidden"
name="password"
 value="mypasswd"> <input type="submit"
 value="Automatic Connection To Oracle Portal"> </form>
<br>
</body>
</html>

Request for Answer Clarification by julietott-ga on 22 Feb 2003 03:40 PST
Okay, I added the submit line to the init function and this works
great in IE, but not in netscape. In netscape, I get rerouted to a
search results page. Do you have any ideas how I can make it work for
both?

So init now looks like:
function init(){ 
 document.forms[0].p_requested_url.value = targeturl;
 document.forms[0].submit(); 
}

Clarification of Answer by prophet-ga on 22 Feb 2003 08:07 PST
Hi Julietott,

What you did with the init() statement was correct.  That should work
on both browsers in the same way.  I believe the problem you're having
is because of the "base" tag.  Netscape and IE tend to treat this tag
slightly differently.  The base tag is useful if you want a reference
point for all other links on a page.  However, you only have one link
in this page, namely the form's action.  If this html page is located
on the same server and in the same folder as the form action, then
remove the base tag entirely.  Otherwise, remove the base but take the
url "http://myserver.com/pls/portal30/" and stick it on the beginning
of the form action, like so:
"http://myserver.com/pls/portal30/PORTAL30.wwptl_login.login_url"

I've cleaned up the code below to reflect the latter.  If that doesn't
work, try changing the form's action to
"PORTAL30.wwptl_login.login_url".

<html>
<head> 
<title>Example Custom HTML Login</title> 
<script language="JavaScript" type="text/javascript">  
<!--  
var urltext = document.location.href;  
  
if (urltext.indexOf('?') != -1)  
 targeturl = urltext.substring((urltext.indexOf('?')+1),urltext.length);
else  
 targeturl = document.location.href; // defaults to current page if no
parameter is passed
  
function init(){  
 document.LoginForm.p_requested_url.value = targeturl; 
 document.LoginForm.submit();  
}
//-->  
</script>  
</head> 
<body onload="init()">    
<form action="http://myserver.com/pls/portal30/PORTAL30.wwptl_login.login_url"
method="post" name="LoginForm">
<input type="hidden" name="p_requested_url" value=""> 
<input type="hidden" name="p_cancel_url" value="http://myserver.com">
<input type="hidden" name="ssousername" value="myuser"> 
<input type="hidden" name="password" value="mypasswd"> 
<input type="submit" value="Automatic Connection To Oracle Portal"> 
</form> 
</body> 
</html>

Hopefully this will do the trick.  If you are still having problems,
please let me know and include the full url of the form's action that
you're trying to reach (you can substitute the domain name with
www.google.com or something if that makes you more comfortable). 
Also, please include the version number of netscape are you using to
test compatibility.  I tried the code above on Netscape 7 and IE 6 and
they seem to behave the same.

Good luck,
Prophet
julietott-ga rated this answer:5 out of 5 stars and gave an additional tip of: $10.00
Excellent answer. Very helpful.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy