/    Sign up×
Community /Pin to ProfileBookmark

Adding script to a popup window

I have a javascript which loads a popup using a string containing the HTML as below:

[code=html]
function openFrameless(){
if (beIE){
NFW = window.open(“”,”popFrameless”,s) //”fullscreen,”+
NFW.blur()
window.focus()
NFW.resizeTo(windowW,windowH)
NFW.moveTo(windowX,windowY)
var frameString=”<html>”+
“<head>”+
“<title>”+title+”</title>”+
“</head>”+
“<body topmargin=”0″ leftmargin=”0″ onbeforeunload=javascript:”CheckIt()”>”+
“”+
“</body>”+
“</html>”;
NFW.document.open();
NFW.document.write(frameString);
NFW.document.close();
} else {
NFW=window.open(urlPop,”popFrameless”,”scrollbars,”+s);
NFW.blur();
window.focus() ;
NFW.resizeTo(windowW,windowH);
NFW.moveTo(windowX,windowY);
}
NFW.focus();
}

[/code]

However, I now want to add javascript to this popup so that before the window closes, a Yes-No box telling the user that they could lose their data. I’ve been trying to simply add the code within quotes in the code above, but I get an error on the page when I view it. Can someone please help me with this?

Chris

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@phpnoviceJun 07.2005 — When you add the code, you just have to split the word "script" to prevent these errors:

var str = '<scr'+'ipt type="text/javascript">...</scr'+'ipt>';
Copy linkTweet thisAlerts:
@chrscoteauthorJun 08.2005 — Cool!! Thank you very much!! I couldn't figure out why my code wasn't working since it looks right.

Chris
Copy linkTweet thisAlerts:
@phpnoviceJun 08.2005 — Cheers.
Copy linkTweet thisAlerts:
@BigMoosieJun 08.2005 — I dont know why people bother concatenating:

"&lt;/SCR"+"IPT&gt;";

when this is just as good but cleaner:

"&lt;/SCRIPT&gt;";
Copy linkTweet thisAlerts:
@chrscoteauthorJun 08.2005 — I have another question now... Is there a command to stop a window from closing?

I have a window that is displayed as a popup in which I have a Flash swf with its own close button. When they close Flash's close button, I need to save some data that is on the page. I want to display an alert to the user if they click the Windows X button telling them to use the Flash version and stop the close action.


Chris
Copy linkTweet thisAlerts:
@BigMoosieJun 08.2005 — You can use window.onunload but you cannot stop the user from closing the window manually.
Copy linkTweet thisAlerts:
@phpnoviceJun 08.2005 — I have another question now... Is there a command to stop a window from closing? [/QUOTE]
I haven't tried it myself -- and wouldn't consider doing so either; however, there is the [b]onbeforeunload[/b] event in which I believe you can return a [b]false[/b] value to the event to prevent the window from closing. At least IE supports this. Possibly no other browser does, though.

The intent of this event is to allow your own code to perform cleanup before allowing the window to continue to close. However, a confirmation prompt as warning to the user before data is lost may also be a valid use of this event. But, again, probably IE-only.
Copy linkTweet thisAlerts:
@phpnoviceJun 08.2005 — I dont know why people bother concatenating:

"&lt;/SCR"+"IPT&gt;";

when this is just as good but cleaner:

"&lt;/SCRIPT&gt;";[/QUOTE]

Well, it's like this... Three additional backslashes strewn throughout the string as opposed to a sequence of three concatenation characters all together in one place... Seems to me the concatenation is cleaner. Of course, each to their own. Perhaps one should keep that in mind before attempting to throw stones. ?
Copy linkTweet thisAlerts:
@BigMoosieJun 08.2005 — Well, it's like this... Three additional backslashes strewn throughout the string as opposed to a sequence of three concatenation characters all together in one place... Seems to me the concatenation is cleaner. Of course, each to their own. Perhaps one should keep that in mind before attempting to throw stones. ?[/QUOTE]

It can be </script> if you want it to ? but my program then colour codes everything wrong while I edit it so I become accustome to 3 slashes.
×

Success!

Help @chrscote 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 6.1,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...