Jump to content


Embedded HTML With XHTML Parsers


2 replies to this topic

#1 worldnet

    Young Padawan

  • Members
  • Pip
  • 2 posts

Posted 25 May 2009 - 12:51 PM

I've got some code I wrote in PHP that will generate a new argument
string for the browser, but the xhtml parser in Firefox and Opera both
complain about my use of &var=value pairs.

Below is my code that generates the string :

function InvokeURL(url_to_forward_to)
{
try
{
var xfamElem = document.getElementById('xFamily');
var mainform = document.getElementById('mainform');
var new_url = url_to_forward_to + "&variable=" + xfamElem.value;

mainform.action = new_url;
mainform.submit();
}
catch(error)
{
alert("InvokeURL encountered an error :" + error.description);
}
}

This works fine with *many* browsers except the new ones.. With IE on
windows (IE6) and Opera, Firefox all complain, Safari and some older
browsers seem to work OK..

If I change the line with the new_url variable setting on it to use a
& instead, it passes the XHTML tests but no longer works at all.. When
using the & it still has that in the URL that shows in the address
bar and hence it seems to cause the script on the other end a lot of
problems as it is unable to properly parse the URL string.

Any ideas on how to portably get around this problem with embedded &
created URL's?

Thank you,
Van

Edited by worldnet, 26 May 2009 - 12:11 PM.


#2 Wybe

    Jedi In Training

  • Members
  • PipPip
  • 399 posts
  • Gender:Male
  • Location:the Netherlands
  • Interests:Graphic design, digital and traditional, street style, graffiti, guerilla drawing, typography, coding, sex

Posted 25 May 2009 - 06:52 PM

just a quick little something, i don't remember running into this problem, could it have something to do with use of single quotes?

like
var new_url = url_to_forward_to + '&variable=' + xfamElem.value;

instead of
var new_url = url_to_forward_to + "&variable=" + xfamElem.value;

#3 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 25 May 2009 - 10:44 PM

Try:
var new_url = url_to_forward_to + '\046variable=' + xfamElem.value;
Ideally it will avoid all problems by using the octal value of '&'. I've never tried it in the context you are using it, but it could work.

I'm not sure if JS distinguishes between quote types though.

Edited by rc69, 25 May 2009 - 10:45 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users