Important: Starting with QuickTime 7.1.5, you can no longer issue javascript:// URLs or call JavaScript functions directly from within a QuickTime movie. This feature was removed from QuickTime for security reasons. If you need to call a JavaScript function from a movie, the recommended practice is to load an HTML page into an Iframe, and call the JavaScript function in the ONLOAD parameter of the Iframe page.
Several things can cause QuickTime to send a URL to the browser, such as the user clicking a hotspot in a QuickTimeVR panorama, clicking a movie that has an associated HREF, loading a sample in an HREF track (a type of text track containing URLs), or as the result of a wired action. Wired actions can be triggered by user interaction, as a result of a frame in the movie being displayed, or as the result of arbitrary wired calculations.
Sending URLs to a browser is supported in QuickTime 3 and later for movie HREFs, visual track HREFs, HREF track HREFs, and VR hotspots. Wired sprite actions in general are supported in QuickTime 4 and later (new wired actions have been introduced with various releases of QuickTime, so a particular wired action may require a later QuickTime version).
Sending javascript: URLs directly to the browser as part of a QuickTime URL is no longer supported.
In order to execute a JavaScript function from a movie in QuickTime 7.1.5 or later, you must load an HTML page that calls the desired JavaScript function. One way to make the user experience as seamless as possible is to load an HTML page into a hidden Iframe, with a single JavaScript function defined in the <head> element, set to execute onload. This way, loading the page is essentially the same as executing the JavaScript function.
If you need to call a JavaScript function defined on page that loads the movie, call it from the Iframe page using parent.FunctionName() addressing syntax.
For example, suppose you have a JavaScript function called MyFunction() that you wish to call from QuickTime. In the past you could call it directly. Now, you must call it indirectly. Here's how:
In the page that contains MyFunction(), create an invisible Iframe, like this:
<iframe id="Iframe1" name="Iframe1" |
frameborder="0" vspace="0" hspace="0" |
marginwidth="0" marginheight="0" width="0" height="0" |
src="blank.html"> |
</iframe> |
Note that the Iframe needs an initial source URL. This example uses "blank.html", an html page that has no content:
<HTML> |
<HEAD> <TITLE>blank.html</TITLE> </HEAD> |
<BODY> </BODY> |
<HTML> |
Create a page intended to load into the Iframe. This page contains a single JavaScript function that calls MyFunction(). This new function, named CallMyFunction(), is called when the page loads, using the onload attribute of the <BODY> tag:
<HTML> |
<HEAD> |
<TITLE>callmyfunction.html</TITLE> |
<Script language="javascript" type="text/javascript"> |
function CallMyFunction() |
{ parent.MyFunction(); } |
</Script> |
</HEAD> |
<BODY onload="CallMyFunction()"> </BODY> |
</HTML> |
Modify the URL called by the movie, from "javascript:MyFunction();" to "<http://CallMyFunction.html> T<Iframe1>"
This changes the URL from javascript: to http:// protocol, and loads the new page into the Iframe named "Iframe1". The new page calls MyFunction() in the parent page when it loads. For the user, the experience is the same as if the movie had called MyFunction() directly.
The following code example shows two HTML pages. The first page creates an Iframe, defines a function, test(), to be called from QuickTime, and embeds a movie. The second page, which will be loaded into the Iframe, defines a JavaScript function, CallParentTest(), that calls the test() function in the parent page. The onload attribute of the BODY tag is set to execute the CallParentTest() function when the second page loads.
Listing 1-2 Executing a JavaScript function from QuickTime using an invisible Iframe
<html> |
<head> |
<Title>calltest.html (Page That Executes JavaScript test() Function Indirectly)</Title> |
<script language="javascript" type="text/javascript"> |
function CallParentTest() |
{ |
parent.test(); |
} |
</script> |
<body onload="CallParentTest()"> |
</body> |
</html> |
<html> |
<head> |
<Title><Page that contains in invisible iFrame> |
<script src="AC_QuickTime.js" language="javascript" type="text/javascript"> </script> |
<script language="javascript" type="text/javascript"> |
function test() |
{ |
alert("JavaScript function called from QuickTime!"); |
} |
</script> |
</head> |
<body> |
<h2>This Movie Calls JavaScript idirectly using an Iframe</h2> |
<iframe id="Iframe1" name="Iframe1" frameborder="0" vspace="0" hspace="0" marginwidth="0" marginheight="0" width="2" height="2" src="blank.html"> |
</iframe> |
<script language="javascript" type="text/javascript"> |
QT_WriteOBJECT('MyMovie.mov' , '320', '240', '', 'HREF', '<Calltest.html> T<Iframe1>'); |
</script> |
<p>Click on the display portion of the movie to execute the JavaScript alert() function. |
</p> |
</body> |
</html> |
You can use this technique to execute any number of JavaScript functions from a movie. Just call each JavaScript function from its own HTML page with the page set to execute the function using the onload attribute of the <body> element. The JavaScript function can be defined entirely within the Iframe page, or it can call other JavaScript functions defined on the parent page using the parent.functionName() syntax.
Call the URL of the page with the target set to the name of the Iframe. Note that the syntax for specifying the URL includes the target Iframe: ‘<url> T<frameID>’. This is true whether the URL is invoked from an HREF, QTNEXTn, or HOTSPOT parameter, for example.
Important: A URL called from QuickTime cannot cross local/remote zone boundaries. If the movie is loaded using a remote protocol, such as http://, any URL called from the movie must also use a remote protocol (http:// or https:/ or rtsp://). A movie loaded via http:// cannot call a file:/// URL. Similarly, if the movie is loaded using a local file:/// URL, it cannot call a remote URL (http://, for example).
Last updated: 2008-02-08