CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
passing javascript vars to perl cgi scripts

 



adrockjames
stranger

Dec 4, 2001, 7:02 PM

Post #1 of 4 (581 views)
passing javascript vars to perl cgi scripts Can't Post

hi,

this might be more appropriate in the javascript section, but as the last post was nov., thought i would try here.

i have a link on a web page that calls a javascript function which in turn calls a perl cgi script that presents a form. in the js function, i want to pass the originating url to the cgi.
like cgi?ul=http://url.javascriptfunction.was.called.from/

i have this function, but can't get it to pass the url... can anyone help?

function newWin() {

var url= "" + opener.<something>.<something>;

aWindow = window.open("http:\/\/www.mypage.com\/cgi\/form.cgi?ul=url","","toolbar=no,location=no,directories=no,status=no,menubar=1,scrollbars=no,resizable=yes,width=400,height=550");

}

thanks in advance!



yapp
User

Dec 5, 2001, 1:52 AM

Post #2 of 4 (578 views)
Re: passing javascript vars to perl cgi scripts [In reply to] Can't Post


Code
function newWin() { 
var url= opener.location.href;

url = "http:///www.mypage.com/cgi/form.cgi?url=" + escape(url)

// If you put a target name in the 2nd parameter, the window will be opened once.
var popup = window.open(url, "thewindow", "menubar,resizable,width=400,height=550");

if(popup.opener == null) {
// ie3 fixes
popup.opener = self;
popup.location.href = url // you properly need to test this aswell before assiging,
// like I did with the window.opener

}

window.focus(); // when re-opened you need to focus
}

Still, what are you trying to do? Does the previous code answer your question?.


Tip: If you need to send a POST request to your script (and not a GET request), you need to do something else, like

Code
HTML 

<FORM name="hiddenform" method="POST" action="/cgi-bin/form.cgi">
<INPUT type="hidden" name="url" value="">
</FORM>

...

JavaScript
function sendIt(url) {
document.hiddenform.url = url // don't escape()
document.hiddenform.submit();
}

Yet another Perl Programmer

_________________________________
X-Forum - Members and testers wanted Wink


adrockjames
stranger

Dec 5, 2001, 7:57 AM

Post #3 of 4 (575 views)
Re: passing javascript vars to perl cgi scripts [In reply to] Can't Post

thanks! yes it does help, however on the page i get an error that

'opener.location' is null or not an object.

here's how i call the function

<a href="javascript:newWin()" onMouseover="window.status=' '; return true">

i'm using ie5.5 on NT with your code in place

thanks again




yapp
User

Dec 5, 2001, 8:04 AM

Post #4 of 4 (573 views)
Re: passing javascript vars to perl cgi scripts [In reply to] Can't Post

Sorry. This var url= opener.location.href should be replaced by var url = window.location.href. If the current window isn't opened, window.opener is null (and not an object you can ask the location.href from).

P.S. Have you even seen this code:

Code
html 
<A href="a/file.html" target="newWindowName" onClick="return OpenPopup(this)">a file</A>

JavaScript
function OpenPopup(linkObject) {
var url = linkObject.href;
var target = linkObject.target || '';
window.open(url, target, ..................)
.............
return false; // there is no reason why
// the <A href> tag should be executed

}

That's also compatible with non-js browsers.

Yet another Perl Programmer

_________________________________
X-Forum - Members and testers wanted Wink

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives