Results 1 to 2 of 2

Thread: mixes java with javascript to manage the evenements into iframe

  1. #1
    Join Date
    Aug 2014

    Unhappy mixes java with javascript to manage the evenements into iframe

    I have a big problem and I do not know if it can be resolved or not. I want to manage the behavior of a user in the iframe (when he moves the mouse or click on or select a text from this iframe) but the problem I have to do a treatment session to the user, so I have to handle mouse events via servlets, but it seems impossible. Now I'm trying to use Javascript but I'm not sure if I can get the servlet session and also transmit to the servlet. please get an idea about this problem. This is my JSP page I just tried here to test the selection of the text but it does not work. And what about calling the session in JavaScript if it is possible.

    this piece of code will detect the text selected by the user in the iframe, I tried thousands of codes with nothing.
    HTML Code:
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
         <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
     <head >
            <meta charset="utf-8" />
            <title>FUZZY SEARCH ENGINE</title>
            <link type="text/css" rel="stylesheet" href="inc/style.css" />
    <body id="page2">
    <div style="margin-top:90px"> <span style="color:#FFFFFF; font-size:30px; letter-spacing:10px; margin-left:555px;">The fuzzy search engine</span>
    <form method="post" action="Open">
     <input Name="Button_save" type="submit"  value="" id="save" >
     <input Name="Button_imprime" type="submit" value="" id="imprime">
     <input Name="Button_back"  value="" type="submit" id="back" >
    <iframe style="width: 1331px;  height:600px;" src="${url}"></iframe>
    <script type="text/javascript">
    function function(){
         var String selectedtext;
        var frame = document.getElementById(myframe);
        var frameWindow = frame && frame.contentWindow;
        var frameDocument = frameWindow && frameWindow.document;
        if (frameDocument) {
            if (frameDocument.getSelection) {
                // Most browsers
            else if (frameDocument.selection) {
                // Internet Explorer 8 and below
              selectedtext= frameDocument.selection.createRange().text;
            else if (frameWindow.getSelection) {
                // Safari 3

    For the code I want to integrate the javascript function is as follows
    HTML Code:
    <%  HttpSession session = request.getSession();%>
                <%com.onto.beans.Document doc=session.getAttribute("sessiondoc"); %>
                <% doc.setNbre_caractère_sélectionné(selectedtext.length());%>
    //selectetedtext variable with JavaScript code.

  2. #2
    Join Date
    Jan 2005
    I can imagine how your Java background may be confusing you, but in JS you must be careful how you use keywords. So, lets start out by changing
    "function function(){"
    to something a bit more logical, such as:
    "function checkIframeText(){"
    You also need to change this wherever it is that you are calling the function from - although I cannot spot that anywhere...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center