/    Sign up×
Community /Pin to ProfileBookmark

document.write on popup in IE problem

i would like to popup a window and document.write with javaScript.
The following works fine on FF, Safari, NS, both on Mac and PC, but fails in IE (6 and 7 as far as i know).
it opens a new window in IE, but it doesn’t write anything. not even title.
any suggestion?

(this is written in xsl, i don’t think it matters. )

[code=html]
<script language=”JavaScript”>
<![CDATA[

function image(Pic,wVal,hVal,pTitle,Name){

subWin = window.open(“”,Name,”width=”+ wVal + “,height=” + hVal +”,top=0,left=0″);
subWin.document.open();
subWin.document.write(‘<html><head><title>’+pTitle+'</title>’);
subWin.document.write(‘</head><body background=”‘+ Pic +'”>’);
subWin.document.write(‘</body></html>’);
subWin.document.close();
subWin.focus();

}
]]>
</script>

[/code]

thanx or your help.

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@FangSep 26.2007 — What argument values are you passing?
Copy linkTweet thisAlerts:
@deluxmilkmanauthorSep 26.2007 — Pic = 'pic1.jpg'

wVal = 500

hVal = 500

pTitle = 'nw_one'

new window opens in 500 x500.

window open
Copy linkTweet thisAlerts:
@FangSep 26.2007 — IE doesn't like the '.' in windowName 'pic1.jpg'

Best to use alphanumeric characters.
Copy linkTweet thisAlerts:
@deluxmilkmanauthorSep 26.2007 — oh, i was posting my old code.

i was using Name (nw_one) fow window name, nut still not working.
Copy linkTweet thisAlerts:
@harumphSep 26.2007 — Why do you have this line in there?

subWin.document.open();

Shouldn't it work without it?
Copy linkTweet thisAlerts:
@harumphSep 26.2007 — I don't have experience with xsl, but this code works fine living in a normal page without the xsl stuff.

Do you have to have the <![CDATA[

and ]]> for it to work in xsl? I've seen it without it or can't you just call this within a general xsl wrapper? <xsl:template> javascript </xsl:template>

Or I've seen it done like this date script:

[CODE]<xsl:script
implements-prefix="date"
language="javascript">

function clock() {
var time = new Date();
var hours = time.getHours();
var min = time.getMinutes();
var sec = time.getSeconds();
var status = "AM";
if (hours > 11) {
status = "PM";
}
if (hours < 11) {
hours -= 12;
}
if (min < 10) {
min = "0" + min;
}
if (sec < 10) {
sec = "0" + sec;
}
return hours + ":" + min + ":" + sec + " " + status;
}


</xsl:script>

[/CODE]
Copy linkTweet thisAlerts:
@harumphSep 26.2007 — I would like to learn this. Where is the best place to learn XLS?

Maybe this helps?
Copy linkTweet thisAlerts:
@Arty_EffemSep 26.2007 — oh, i was posting my old code.

i was using Name (nw_one) fow window name, nut still not working.[/QUOTE]
There must be something wrong with the resultant parameters.

I.E. won't allow spaces or dashes in the [I]name[/I] parameter.

Are you getting any error messages in the console?
[CODE]<html>
<head>
<title>Test</title>
<script type="text/javascript">

function image(Pic, wVal, hVal, pTitle, Name)
{
subWin = window.open("", Name.replace(/[s-]/g,'_'), "width="+ wVal + ",height=" + hVal +",top=0,left=0");
subWin.document.open();
subWin.document.write('<html><head><title>'+pTitle+'</title>');
subWin.document.write('</head><body background="'+ Pic +'">');
subWin.document.write('</body></html>');
subWin.document.close();
subWin.focus();
}

</script>
</head>

<body><a href="#" onclick="image('pic1.jpg',500,500,'nw_one','picture_1');return false">Open</a>
</body>
</html>[/CODE]
Copy linkTweet thisAlerts:
@deluxmilkmanauthorSep 27.2007 — this worked. thanks everyone.

[code=html]
subWin = window.open("",Name,"width="+ wVal + ",height=" + hVal +",top=0,left=0");
subWin.document.open();
subWin.document.write('<html><head><title>'+pTitle+'</title>');
subWin.document.write('</head><body background="'+ Pic +'">');
subWin.document.write('</body></html>');
subWin.document.close();
subWin.focus();
[/code]
×

Success!

Help @deluxmilkman 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.15,
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,
)...