/    Sign up×
Community /Pin to ProfileBookmark

passing current URL to popup window

Could someone help this total Javascript newbie? I’m trying to do something that appears very simple but in actuality is hurting my brain.

When a user clicks on a specific image map area I want that to open a new window without scrollbars or status bar etc. and it also needs to pass the original page’s URL on to the new popup window for use in a second form. I was trying to use onClick for this but I can’t figure out how to combine opening a new window with passing the URL just using onClick.

In my testing code below I’ve put in a tiny bit of JS to grab the URL and put it into a form variable. Clicking on the first image map area submits the form and opens the resulting page into the original window just fine. Clicking on the second image map opens the new window as desired, but I don’t know how to pass a form variable along with defining the popup window all at once. What direction should I take to make this work? Thanks!

[CODE]<form action=”/popup_form.html” method=”post” name=”passurl” target=”_blank” id=”passurl”>
<input name=”url” type=”hidden” id=”url”>
<SCRIPT LANGUAGE=”javascript”>
var url = window.location
document.passurl.url.value = url
</SCRIPT>
<map name=”Map”>
<area shape=”rect” coords=”608,28,695,49″ href=”#” onClick=”document.passurl.submit()”>
<area shape=”rect” coords=”294,28,465,49″ href=”#” onClick=”PopUp=window.open(‘/popup_form.html’,’Popup’,’scrollbars=no,status=no,resizable=yes,height=320,width=400′);return false;”>
</map>
</form>[/CODE]

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@felgallFeb 11.2006 — To pass the address of the current page use the following slightly modified onclick:

onclick="window.open('/popup_form.html?' + encodeURI(window.location.href),'Popup','scrollbars=no,status=no,resizable=yes,height=320,width=400');return false;"
Copy linkTweet thisAlerts:
@AlanCEauthorFeb 12.2006 — ohhh, is that putting a unicode representation of the original URL in as part of the popup window's url? In the target window, how do i retreive the url that was passed? Is there a way to remove the unicode so it's back in readable form?

thanks Stephen
Copy linkTweet thisAlerts:
@AlanCEauthorFeb 13.2006 — I've been doing a lot of searching and reading on this but can't figure out how to retrieve the url that was passed with the http://xxx? + encodeURI(window.location.href) bit, or whether or not it ends up in some form needing to be unencoded... can anyone comment? Thanks!
Copy linkTweet thisAlerts:
@AlanCEauthorFeb 13.2006 — Okay i think i might have part of the answer; i added "url=" after the question mark in the source file part of window.open. I then use $_GET['url'] in my popup. I still dont understand how the encodeURI thing works though.

[CODE]onclick="window.open('/popup_form.html?url=' + encodeURI(window.location.href),'Popup'[/CODE]

I'll continue with my noobish monologue for the entertainment of whoever wants to read about my struggles coming to grips with javascript. :p
×

Success!

Help @AlanCE spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...