We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,577 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

body onload ... popup window

trying to make this script work:

<script type="text/javascript">
var tmp='<html><head><title>popup</title>';
tmp+='<script type=text/javascript>';
tmp+='function nowTime(){';
tmp+='var oNowTime=new Date();'; 
tmp+='var iMonth=oNowTime.getMonth();';
tmp+='var iDate=oNowTime.getDate();';
tmp+='var iYear=oNowTime.getFullYear();';
tmp+='var iHours=oNowTime.getHours();';
tmp+='var iMinutes=oNowTime.getMinutes();';
tmp+='var iSeconds=oNowTime.getSeconds();';
tmp+='var iMilliSeconds=oNowTime.getMilliseconds();';
tmp+='var sNowTime=iHours+":"+iMinutes+":"+iSeconds;';
tmp+='return sNowTime';
tmp+='}';
tmp+='function nowDate(){';
tmp+='var oNowTime=new Date() ';
tmp+='var iMonth=oNowTime.getMonth()+1';
tmp+='var iDate=oNowTime.getDate()';
tmp+='var iYear=oNowTime.getFullYear()';
tmp+='var iHours=oNowTime.getHours()';
tmp+='var iMinutes=oNowTime.getMinutes()';
tmp+='var iSeconds=oNowTime.getSeconds()';
tmp+='var iMilliSeconds=oNowTime.getMilliseconds()';
tmp+='var sNowTime=iYear+"-"+iMonth+"-"+iDate;';
tmp+='return sNowTime';
tmp+='}';
tmp+='function showNowTime(){';
tmp+='var oObjId1=document.getElementById("mdate");';
tmp+='oObjId1.innerHTML=nowDate();';
tmp+='var oObjId2=document.getElementById("mclock");';
tmp+='oObjId2.innerHTML=nowTime();';
tmp+='setTimeout("showNowTime()",1000)';
tmp+='}';
tmp+='<\/script></head><body onload="showNowTime()">';
tmp+='<font size="7">';
tmp+='<div id="mdate">mdate</div>';
tmp+='<div id="mclock">mclock</div>';
tmp+='</font></body></html>';
    var newwindow2=window.open('','name','height=200,width=150');

    newwindow2.document.write(tmp);

</script>

What's Wrong ??

any suggestions are welcomed.

thanks

2
Contributors
5
Replies
8 Hours
Discussion Span
5 Months Ago
Last Updated
7
Views
Question
Answered
green-script
Newbie Poster
8 posts since Nov 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Line 35 seems to be wrong: tmp+='<\/script>

AleMonteiro
Master Poster
752 posts since Aug 2010
Reputation Points: 129
Solved Threads: 140
Skill Endorsements: 23

thank you for your response

but, most browsers won't allow unescaped </script> tags even in JS strings.
so must escape the slash, <\/script>

any other suggestions???

green-script
Newbie Poster
8 posts since Nov 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Can't you have another page to be loaded in the new window? Why do you have to write it in JS?

Even if need to pass any data you can do it later. If both pages are in the same domain you can interact with each other with JS.

AleMonteiro
Master Poster
752 posts since Aug 2010
Reputation Points: 129
Solved Threads: 140
Skill Endorsements: 23

Can't you have another page to be loaded in the new window

yes . it's the best and most popular way, with two webpage ...etc.

thanks alot

green-script
Newbie Poster
8 posts since Nov 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 5 Months Ago by AleMonteiro

Yes, it's used a lot.

But I don't really like it. I prefer to use popup dialogs in the same window, with divs

AleMonteiro
Master Poster
752 posts since Aug 2010
Reputation Points: 129
Solved Threads: 140
Skill Endorsements: 23

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0723 seconds using 2.68MB