How to prevent the symbol "&" from being replaced by "&"

tonyf picture tonyf · Jun 8, 2010 · Viewed 13.3k times · Source

I am looking to prevent the symbol "&" from being replaced by "&" within my URL, specifically within JavaScript.

Just to expand on this requirement, I am getting my url from an oracle database table, which I then use within Oracle Application Express, to set the src attribute of an iframe to this url.

FYI, the url stored in the Oracle table is actually stored correctly, i.e.

http://example.com/xml/getInfo?s=pvalue1&f=mydir/Summary.xml

What appears in my use when trying to pass over into iframe src using JavaScript is:

http://example.com/xml/getInfo?s=pvalue1&f=mydir/Summary.xml

which basically returns a page cannot be found

Answer

Tony Andrews picture Tony Andrews · Jun 8, 2010

I suspect you are doing something like this:

1) Selecting the URL text from the database into an Apex page item.

2) In Javascript, getting the URL text from the page item and using it to set the iframe source.

When you select the value in step 1, Apex will automatically replace the "&" by "&" so that the page HTML is valid - it will be something like:

<input type="hidden" id="P1_URL" 
 value="http://mydomain.com/xml/getInfo?s=pvalue1&amp;f=mydir/Summary.xml" />

You will therefore have to reverse the transformation in your Javascript code - something like:

document.getElementById('myIframe').src = $v('P1_URL').replace('&amp;','&');