PDA

View Full Version : document.open --> permission denied


GnomeKing
09-27-2002, 10:59 AM
I have a problem with document.open

I have two frames, and I wish for the top frame to be able to document.open and document.write into the bottom frame

If I do not load a URL into the bottom page, I can do it fine - but I want to be able to do it after something has been loaded into the bottom page - does anyone have any suggestions?

The desired effect is for the second page to be completely blanked when I'm doing this - so if I manage to do a document.open, I'd do a document.clear straight away - so theres no need to preserve the information in the 2nd frame

thanks for your help

glenngv
09-27-2002, 11:03 AM
you cannot do it if the bottom frame is on a different domain.

GnomeKing
09-27-2002, 11:06 AM
Originally posted by glenngv
you cannot do it if the bottom frame is on a different domain.

I can set the location to anything - cant I? so I can load a new URL into the bottom frame - but I tried loading something from the same domain and then document.opening, and that didnt work (even in the same directory - it still said permission denied)

glenngv
09-27-2002, 11:11 AM
can you post the code?

GnomeKing
09-27-2002, 11:18 AM
Summary:

Type in a string of characters into the edit box and it displays a list of all matches in functions.js which start with the same letters


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>

<head>

<title>Functions</title>

<style type="text/css">
body {background:gainsboro}
</style>



<script language="javascript">

// Min number of chars needed before a list is displayed.
var mincharsforlist = 4;

</script>


<script language="javascript">

// Flag to indicate name,url data has been loaded.
var loaded = false;

// Define variables for the name,url data.
var names; names = new Array();
var urls; urls = new Array();

//
// error_flash : change text box background to red and back to white.
//
function error_flash()
{
window.document.all.mytextbox.style.background = "#ff0000";
setTimeout("window.document.all.mytextbox.style.background = '#ffffff';",200);
}


function loadpage(name,url)
{
window.document.myform.mytextbox.value = name;
parent.mainframe.location = url;
parent.mainframe.focus();
window.document.myform.noframebutton.disabled=false;
}

function unloadpage()
{
window.document.myform.noframebutton.disabled=true;
}



function process_backspace()
{
var text, newtext;

//alert(window.document.selection.text);

text = window.document.myform.mytextbox.value;
if(text.length > 0)
{
window.document.myform.mytextbox.value = "";
newtext = text.substr(0, text.length-1);
window.document.myform.mytextbox.value = newtext;
}
return true;
}

//
// process_keypress: process the current text + any key-press
// text : value in the text box before the key press
// keycode : key-code of the key pressed. (0=no key pressed)
// complete : boolean. If true, complete the typed name as
// much as possible, and display a name list.
//
function process_keypress(text, keycode, complete)
{
var nextchar, fulltext, thename, searchname;
var found, finished;
var i, j, k, charsmatched;
var foundidx;

// If the name-url data has not finished loading,
// return true. This will allow any character typed
// to be displayed in the text box.
if (!loaded) {return true;}

// Add the key press to the name string, and convert to lowercase.
if (keycode != 0) nextchar = String.fromCharCode(keycode);
else nextchar="";
fulltext = text + nextchar;
thename = fulltext.toLowerCase();

// Search for the first and last name matching the name string.
found = 0;
for(i=0; i < names.length; i++)
{
if (names[i].indexOf(thename) !=-1)
{
found = found + 1;
foundidx[found] = i;
}
}

// If any matches were found..
if (found>=1)
{
// Only one match: load a page from the corrsponding URL
if(found==1)
{
loadpage(thename,urls[foundidx[i]]);
return false;
}

// More than one match: display a list of matches
else
{
// Display a list of matching names, but only if
// completing names or if a minimum
// number of characters has been typed.
if (thename.length >= mincharsforlist)
{
unloadpage();
parent.mainframe.document.open();
for(k=1; k<=found; k++)
{
parent.mainframe.document.write("" +
"<A href=\"#\" " +
"onClick=\"return parent.textboxframe.process_keypress('" + names[k] + "',0,true);\">" +
names[foundidx[k]] + "</A>\n");
}
}
// Keep the focus in the text box to allow more typing.
parent.textboxframe.document.myform.mytextbox.value = thename;
parent.textboxframe.document.myform.mytextbox.focus();
}
}

// No match
else
{
// Keep the focus in the text box to allow more typing.
error_flash();
window.document.myform.mytextbox.focus();
}

return false;
}

function onloadfn()
{
loaded = true;
// Sorry you can't do this in IE4.
//document.all.the_data.src="http://localhost/functions.js";
}

</script>

<!-- The name-url data.-->
<!-- It doesn't work in IE4 -->
<script id="the_data" src="http://localhost/a.js"></script>


</head>


<!----------------------------------------------------------------------->


<body onLoad="onloadfn();">

<!-- Display the form before anything else -->

<form name="myform"
onSubmit="process_keypress(mytextbox.value,0,true); return false;">

Function:

<input name="mytextbox" type="text" size="25"
onKeyPress="return process_keypress(mytextbox.value,event.keyCode,false);"
onKeyDown= "if (event.keyCode==8) return process_backspace();" />

<input type="button" value="Modules"
onClick="parent.location='http://localhost/modules_frame.html'" />

<input type="button" value="No Frame" id="noframebutton" name="noframebutton"
onClick="parent.location=parent.mainframe.location.href;" />

</form>

<!-- Focus ready for typed input -->
<script>
unloadpage();
parent.textboxframe.document.myform.mytextbox.focus();
</script>

<!- We have to bring in the data at load time in IE4 -->
<script src="http://localhost/functions.js"></script>

</body>

</html>