Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old June 3rd, 2005, 08:39 AM
Authorized User
 
Join Date: Jun 2003
Location: Jewett City, CT, USA.
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default Adding javascript to popups

I have a stand-alone Flash training application that is opened as a popup from another HTML page. If the student clicks on the Windows close button, I want to have an alert telling them that they're not allowed to do that. I've been trying to add a fairly simply javascript to the popup code, but I keep getting errors saying that I have an "Unterminated string constant" on the line that reads:
        "<script>"+

Here is a portion of the code:
function openPop() {
    NFW = window.open("","popFrameless",s)
    NFW.blur()
    window.focus()
    NFW.resizeTo(windowW,windowH)
    NFW.moveTo(windowX,windowY)
    var frameString="<html>"+
    "<head>"+
    "<title>"+title+"</title>"+
    "<script>"+
    "function checkExit() {"+
    " //Do something here
    "}"+
    "</script>"+
    "</head>"+
    "<body onBeforeUnload=\"javascript:checkExit()\"></body></html>"
    NFW.document.open();
    NFW.document.write(frameString);
    NFW.close();
    }
}

Is there a way I can get around these errors?

Chris

  #2 (permalink)  
Old June 8th, 2005, 01:09 AM
Registered User
 
Join Date: Jun 2005
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

<HEAD>

<SCRIPT>

var windowW=214
var windowH=398
var windowX = 260
var windowY = 100
var urlPop = "http://www.yahoo.com"
var title = "PopUp Window!"
var autoclose = true

s = "width="+windowW+",height="+windowH;
var beIE = document.all?true:false
function openFrameless() {
if (beIE) {
NFW = window.open("","popFrameless","fullscreen,"+s);
NFW.blur();
window.focus();
NFW.resizeTo(windowW,windowH);
NFW.moveTo(windowX,windowY);
var frameString=""+
"<html>"+
"<head>"+
"<title>"+title+"</title>"+
"</head>"+
"<frameset rows='*,0' framespacing=0 border=0 frameborder=0>"+
"<frame name='top' src='"+urlPop+"' scrolling=auto>"+
"<frame name='bottom' src='about:blank' scrolling='no'>"+
"</frameset>"+
"</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();
if (autoclose) {
window.onunload = function(){NFW.close();}
   }
}

</script>

</HEAD>


<BODY onLoad="top.window.focus()">


<a href="javascript:openFrameless()">Click Here</a>


  #3 (permalink)  
Old June 8th, 2005, 04:34 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

When writing script via a string you break up the script word to prevent confusing the parser:
Code:
"<script>" ... "</script>"
=>code]
"<scr" + "ipt>" ... "</scr" + "ipt>"
[/code]
I believe it's not necessary for both but I do it anyway as I can never remember which one...

--

Joe (Microsoft MVP - XML)


Similar Threads
Thread Thread Starter Forum Replies Last Post
adding checkbox to datagrid using javascript k.manisha ASP.NET 1.0 and 1.1 Professional 0 June 4th, 2007 11:02 PM
adding items to list box using javascript k.manisha ASP.NET 1.0 and 1.1 Professional 3 February 16th, 2007 06:32 AM
adding php code in javascript chayanvinayak Javascript How-To 2 December 18th, 2006 02:33 AM
POPUPS venks11 Classic ASP Basics 1 December 6th, 2005 06:56 AM
adding a class in JavaScript crmpicco Javascript How-To 5 October 4th, 2005 08:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.