Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5929307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:24:18+00:00 2026-05-22T14:24:18+00:00

I’m trying to write a script for drag and drop of image in a

  • 0

I’m trying to write a script for drag and drop of image in a iframe in Chrome.

<html>
<head>
    <script language="JavaScript">

        function InsertImage(ev)
        {
            alert("drag function called");
            var _image = document.createElement("image");
            var _sel = _win.getSelection();
            if(!_sel.isCollapsed)
            {
                _sel.deleteFromDocument();
            }
            try{
                var _range = _sel.getRangeAt(0);
            }
            catch(e)
            {
                _range = _doc.createRange();
                alert("000000:::: "+e);
                alert("_range is ::"+_range);
            }
            if(!_range)
            {
                _range = _doc.createRange();
            }
            alert("range is ::::"+_range);
            try
            {
                _range.insertNode(_image);
            }
            catch(e)
            {
                alert("1111::  "+e);
            } 
            _range.insertNode(_image);


        }

        function init()
        {
            _iframe =   document.createElement("iframe");
            _iframe.id = "view";
            _iframe.style.height = "250px";
            _iframe.style.width = "600px";
            _iframe.style.top =   "20px";
            _iframe.style.left = "200px";
            _iframe.style.position = "absolute";
            _iframe.style.border = "2px solid lightBlue";
            document.body.appendChild(_iframe);
                _iframe.contentDocument.designMode="on";//No I18N
                _win = _iframe.contentWindow;
                _win.focus();
                _doc = _win.document; //making it global variable

                _doc.body.innerHTML = "<p>aaaa bbbb cccc dddd eeee ffff gggg hhhh iiii jjjj kkkk llll mmmm nnnn oooo pppp qqqq rrrr ssss tttt uuuu vvvv wwww xxxx yyyy zzzz</p>";
                _doc.addEventListener("dragover",InsertImage,false);

        }

    </script>
</head>
<body onLoad="init()">
    <div style="position:absolute;top:300px;left:100px ">
        <p> this si a testing doc.here, we test the things</p>
    </div>
</body>

Is is not working..
In chrome console , I get this error message:

Uncaught Error: WRONG_DOCUMENT_ERR: DOM Exception 4

Something wrong with selection and range, i guess.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:24:18+00:00Added an answer on May 22, 2026 at 2:24 pm

    A DOMException.WRONG_DOCUMENT_ERR exception is thrown whenever a DOM manipulation method tries to work with nodes that are part of two different DOMDocuments. You must use the DOMDocument.importNode method in order to import a DOMNode from one document to another.

    I suppose you have to import the image-node to the iFrame-document

    something like (untested):

    var nodeToImport = _doc.importNode(_image, true);
    //nodeToImport can now be added to the second document
     _doc.appendChild(nodeToImport);
    

    more here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I used javascript for loading a picture on my website depending on which small
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.