Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > script crash explorer but not mozilla`

Reply
Thread Tools

script crash explorer but not mozilla`

 
 
thomas
Guest
Posts: n/a
 
      11-10-2003
HI
I've written a simpole script to open a new window with an image and
resize the window depending on the image size: it is

function fitToSize()
{
if( window.document.images )
window.resizeTo(window.document.images[0].width+100,
window.document.images[0].height+50);
}

function animUrl(url)
{
var p = 'scrollbars=yes,resizable=yes,toolbar=no,' +
'menubar=no,status=no,location=no,left=85,top=20';

var win = window.open("","animWindow",p);
win.document.writeln('<html>');
win.document.writeln('<head>');
win.document.writeln('<link type="text/css" rel="stylesheet"
href="../style/styleThomas.css">');
win.document.writeln('<script
src="../js/animWindow.js"></script>');
win.document.writeln('</head>');
win.document.writeln('<body id="animWindow"
onload="fitToSize();">');
win.document.writeln('<img name ="imgTag" class="center" src="' +
url + '">');
win.document.writeln('<p><a href="javascript:;"
onclick="self.close();">Close window</a></p>');
win.document.writeln('</body>');
win.document.writeln('</html>');
win.document.close();
//win.resizeTo(win.document.images[0].width,200);
win.focus();

return false;
}

It is very simple. I call it with the following in the html pages:
<a href="javascript:;" onclick="return animUrl('image.gif');">A Gif
image</a>

Clicking on the link crash explorer that immediately freezes.
It works well everywhere else, excpet Opera that complain with an
obnoxious message.

Does anybody see what's obviously wrong in my code?
Thanks

Thomas
 
Reply With Quote
 
 
 
 
Michael Winter
Guest
Posts: n/a
 
      11-10-2003
"thomas" wrote on 10/11/2003:

> HI
> I've written a simpole script to open a new window with an image and
> resize the window depending on the image size: it is
>
> function fitToSize()
> {
> if( window.document.images )
> window.resizeTo(window.document.images[0].width+100,
> window.document.images[0].height+50);
> }
>
> function animUrl(url)
> {
> var p = 'scrollbars=yes,resizable=yes,toolbar=no,' +
> 'menubar=no,status=no,location=no,left=85,top=20';
>
> var win = window.open("","animWindow",p);
> win.document.writeln('<html>');
> win.document.writeln('<head>');
> win.document.writeln('<link type="text/css" rel="stylesheet"
> href="../style/styleThomas.css">');
> win.document.writeln('<script
> src="../js/animWindow.js"></script>');
> win.document.writeln('</head>');
> win.document.writeln('<body id="animWindow"
> onload="fitToSize();">');
> win.document.writeln('<img name ="imgTag" class="center" src="'

+
> url + '">');
> win.document.writeln('<p><a href="javascript:;"
> onclick="self.close();">Close window</a></p>');
> win.document.writeln('</body>');
> win.document.writeln('</html>');
> win.document.close();
> //win.resizeTo(win.document.images[0].width,200);
> win.focus();
>
> return false;
> }
>
> It is very simple. I call it with the following in the html pages:
> <a href="javascript:;" onclick="return animUrl('image.gif');">A Gif
> image</a>
>
> Clicking on the link crash explorer that immediately freezes.
> It works well everywhere else, excpet Opera that complain with an
> obnoxious message.
>
> Does anybody see what's obviously wrong in my code?
> Thanks
>
> Thomas


I don't get a crash, but I do get an 'access denied' error. I think
it's because of a violation of the 'Same Origin Policy': you can't
access properties in a window or frame that didn't originate from the
same domain as the accessing document. As there is no URL at all, IE
probably assumes that no-one should get access - but that's just a
guess. I had the same problem, but there is a simple solution:
include a variable on the calling page that the image window can use
to get the URL. You could actually write a HTML page (rather that
generate one entirely at run-time) that only fills-in the image
source:

<!-- Your !DOCTYPE, HEAD, BODY, etc. for the image window -->
<SCRIPT type="text/javascript">
<!--
document.writeln( '<IMG src="' + window.opener.imageURL + '">' );
// -->
</SCRIPT>
<!-- The rest of your document -->

Hope you have better luck,
Mike

--
Michael Winter
M.Winter@[no-spam]blueyonder.co.uk (remove [no-spam] to reply)


 
Reply With Quote
 
 
 
 
thomas
Guest
Posts: n/a
 
      11-11-2003
I did exactly what you said and it works.
My only regret is that I have to declare this variable imageURL in
every page that use this script.
But thank you very much, since Explorer does not crash anymore.

Thomas

"Michael Winter" <M.Winter@[no-spam]blueyonder.co.uk> wrote in message news:<16Vrb.1665$(E-Mail Removed)>...
> "thomas" wrote on 10/11/2003:
>
> I don't get a crash, but I do get an 'access denied' error. I think
> it's because of a violation of the 'Same Origin Policy': you can't
> access properties in a window or frame that didn't originate from the
> same domain as the accessing document. As there is no URL at all, IE
> probably assumes that no-one should get access - but that's just a
> guess. I had the same problem, but there is a simple solution:
> include a variable on the calling page that the image window can use
> to get the URL. You could actually write a HTML page (rather that
> generate one entirely at run-time) that only fills-in the image
> source:
>
> <!-- Your !DOCTYPE, HEAD, BODY, etc. for the image window -->
> <SCRIPT type="text/javascript">
> <!--
> document.writeln( '<IMG src="' + window.opener.imageURL + '">' );
> // -->
> </SCRIPT>
> <!-- The rest of your document -->
>
> Hope you have better luck,
> Mike

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Internet Explorer 8: C:\Program Files\Internet Explorer\iexplore.exe vs C:\Program Files (x86)\Internet Explorer\iexplore.exe Nathan Sokalski Windows 64bit 16 02-22-2010 08:31 AM
code displays PDF directly from Windows explorer but not when called by II6 to Internet explorer Ed Hauptman HTML 7 08-07-2009 10:11 PM
Script Works in Explorer but Not in Firefox goober Javascript 6 05-27-2006 02:58 PM
<FAQENTRY> window.open methods causes my script crash in Internet Explorer VK Javascript 6 10-26-2005 10:40 PM
CRASH - DirectX End-User runtime - CRASH - What to to ? reply@newsgroup.please Computer Support 1 01-05-2004 02:55 PM



Advertisments