Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
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
 
Old July 24th, 2006, 05:39 PM
Registered User
 
Join Date: Mar 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default 'window.opener.document' error in IE

I am using a Wordpress plugin for clickable smileys.

When a person comments on my blog, they can click the smiley they want and the code for it is transferred to the textbox.

This works in other browsers, the problem is only in Internet Explorer.

The developer is going to be fixing it, eventually. I'd like to try and fix it now so it at least works on my site.

The error is.
'window.opener.document' is null or not an object

Here is that area of the code.
Code:
        function smileys(tag) {
            tag = ' ' + tag;
            var my_field;
            if (document.getElementById('comment') && document.getElementById('comment').type == 'textarea') {
                my_field = document.getElementById('comment');
            } else if (window.opener.document.getElementById('content') && window.opener.document.getElementById('content').type == 'textarea') {
                my_field = window.opener.document.getElementById('content');
            } else if (window.opener.document.getElementById('comment') && window.opener.document.getElementById('comment').type == 'textarea') {
                my_field = window.opener.document.getElementById('comment');
            } else { return false; }
            if (document.selection && !window.opera) {
                my_field.focus();
                sel = window.opener.document.selection.createRange();
                sel.text = tag;
                my_field.focus();
            } else if (my_field.selectionStart || my_field.selectionStart == '0') {
                var startPos = my_field.selectionStart;
                var endPos = my_field.selectionEnd;
                var cursorPos = endPos;
                my_field.value = my_field.value.substring(0, startPos)
                                + tag
                                + my_field.value.substring(endPos, my_field.value.length);
                cursorPos += tag.length;
                my_field.focus();
                my_field.selectionStart = cursorPos;
                my_field.selectionEnd = cursorPos;
            } else {
                my_field.value += tag;
                my_field.focus();
            }
        }


Thanks for any help!
 
Old July 25th, 2006, 07:57 PM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm just absolutely taking a stab in the dark here, but how about replacing that line of code with these four?

if ((window.opener) && (window.opener.document))
  sel = window.opener.document.selection.createRange();
else
  sel = document.selection.createRange();



Jon Emerson
http://www.jonemerson.net/





Similar Threads
Thread Thread Starter Forum Replies Last Post
window.opener for mozilla jun99 Javascript 3 September 1st, 2009 08:57 AM
window.opener.document.parentWindow in Mozilla Mohammedasslam Javascript 2 June 28th, 2007 01:20 AM
opener.document davidph Javascript 2 May 26th, 2007 01:36 AM
Problem accessing the window.opener.opener maryuob Javascript 3 January 18th, 2006 05:25 AM
window.opener help fs22 Javascript How-To 6 May 9th, 2004 10:50 PM





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