Link to home
Start Free TrialLog in
Avatar of waygood
waygood

asked on

javscript passing url as a parameter gets decoded

Hi people,
I've come across a strange little problem when passing a url into a function which then uses it to change the url of an iframe. For some reason it gets decoded enroute but I don't know why?

basically heres my code:-
<script>
function popup_file(url)
{
      alert(url);
      document.getElementById('fileIF').src=url;
      // other stuff
}
</script>

<a href="javascript:popup_file('download.php?file=F5J%23%23+02+Cleaner.pdf')" >open</a>

When it hits the alert it displays a decoded url (which may just be the alert) BUT when i look at the parameters passed to download.php it says file=F5J

%23 is #

when creating the link in php, I urlencode the filename. But the only way to pass it correctly is to urlencode(urlencode($filename))  but why has popupfile decoded my url in the first place????
Avatar of Tomarse111
Tomarse111
Flag of United Kingdom of Great Britain and Northern Ireland image

Have you tried escaping it?
<script>
function popup_file(url)
{
      alert(escape(url));
      document.getElementById('fileIF').src=escape(url);
      // other stuff
}
</script>

<a href="javascript:popup_file('download.php?file=F5J%23%23+02+Cleaner.pdf')" >open</a>

Open in new window

Avatar of waygood
waygood

ASKER

I've tried that and it escapes the whole url including the script and not just the file parameter
ASKER CERTIFIED SOLUTION
Avatar of raja_ind82
raja_ind82
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial