/    Sign up×
Community /Pin to ProfileBookmark

window.open with url variables

Hello,

i have this code:

echo “<script type=’text/javascript’>openWindow(‘”.$adress.”‘)</script>”;

the $adress send an url with variables like “xpto.com?var=1&varB=2”

Problem is that using window.open always encodes & character to &amp; and the url doesn’t open. I have tried many functions but still doesn’t work.

I have this javascript code:

function convert(str)
{
str = str.replace(/&amp;/g,”&”);
//alert(str);
return str;
}

function openWindow(adress)
{
//document.write(adress);

//endereco = convert(adress);

//unescape(url)
//decodeURI()
//decodeURIComponent()
//html_entity_decode();
//encoded.replace(/&amp;/g, ‘&’);

newwindow=window.open( adress,’PROJECT’,’height=800,width=1000′);

if (window.focus) {newwindow.focus()}
return false;

}

The convert function doesn’t do anything. the commented javascript functions like unescape, etc also doesn’t work. If i do alert(adress) it converts & to &amp; but if i do document.write(adress); it shows correctly. So i assume that some functions encode and others don’t. Meaning that window.open encode by default. It there a way to override this?

Thanks for the attention.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@explorerauthorJul 11.2011 — BTW, the commented functions

//unescape(url)

//decodeURI()

//decodeURIComponent()

//html_entity_decode();

i just didn't put them like that. I tried them like this:

newwindow=window.open( unescape( adress ),'PROJECT','height=800,width=1000');
Copy linkTweet thisAlerts:
@Michael_GJul 11.2011 — One thing you may try is using the PHP function URLEncode, this changes a string to an acceptable URL format, including replacing spaces with %20 and handling other special characters as well. Since your issue appears to be with the javascript itself, I am not sure if this will solve your problem, but it is worth a try. There are also similar functions that accomplish this in COLDFUSION and ASP.NET

Also a Javascript function may be useful, encodeURI function should convert a string into a URL acceptable format, including it will change the ampersand & to %26 which is the proper URL code for that character.

I hope this helps you out, let the forum know if this corrects your web development javascript issue.

Michael G. Workman

[email][email protected][/email]
×

Success!

Help @explorer 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.18,
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,
)...