Document.selection.createRange();
Jul 20, 2005Is there a NS7, Opera7 or Mozilla equivalent for:
document.selection.createRange();
Is there a NS7, Opera7 or Mozilla equivalent for:
document.selection.createRange();
I have a nice Javascript code which allows users to HTML format code in a textarea, similar to the code of Post New Thread page. It works great in Internet Explorer but it does nothing in other browsers.
It seems the problem resides in this two lines:
Code:
a=document.selection.createRange();
seleccio = a.text;
How can I arrange this lines in order to make them cross-browser? I really need this code to work, at least, in current versions of Netscape, Mozilla and Opera.
function spawn(ev){
var oSelect = ''
var oFlag = false;
if (ns4 || ns6)
oSelect = document.getSelection();
else if (ie4 || ie5){
if (!ev)
ev = window.event;
oFlag = true;
oSelect = document.selection;
}
alert(oSelect.type);
}
if (oSelect == '')
return;
else{
//stuff
}
In Netscape 4.8 if text is not selected nothing happens which is what I want. Please
disregard the fact that oSelect.type is not Netscape compatible you are really
seeing only a partial of what I am doing.
The issue here comes from this page: Code:
Is there a way to achieve in Firefox (and other browsers) what I achieve in
IE6 with the document.selection.empty()? I want to be able to empty the
selection every time the user clicks a certain area, thus making it
impossible to select any text in that area. Is there a way to clear the
text selection in Firefox?
Following code i modified to make it work in the firefox browser.
but its not working in firefox
if (document.selection)
{
var objRange = document.selection.createRange();
var sOldRange = objRange.text;
[Code]....
According to Google I'm the first person ever to have had this problem. I'm looking for the Gecko equivalent of document.selection.clear() or (better) document.selection.empty().
I'll try to lay out what I'm trying to do. I register an mouseup handler on the document to fire a function to find what text is selected. Code:
Suppose a HTML document has a iframe. Using javascript,I want to detect ,on load of the html document, whether the body of the iframe document is ready to be displayed.I want to be able to overwrite the the body contents (before it actullay loads) of the iframe.can I do it with jquery? say if ,HTML doc is
Code:
<html><head></head><body><iframe id="ifrmId" src="http://www.google.com" ></iframe></body></html>
i want to save my html document as an microsoft word document will
View 14 Replies View RelatedNormally an SVG document is loaded/parsed/interpreted inside an HTML
document using an 'object' (or 'embed') element, although there are
supposedly other ways too. The problem is, the SVG document must be
static this way.
I want to use the DOM interface to build SVG dynamically inside an HTML
document. I am guessing I can build it inside HTML within an 'object' (or
maybe 'iframe'?) element.
My intentions/goals:
In Javascript, I construct an object 'embedSVG' which has properties and
methods for creating valid SVG elements and setting their attributes and
attribute values.
During construction, the SVG document is created with its root element.
During debugging in FF 2.0 (I'll work on an MSIE-compatible format later),
I am using the Mozilla DOM Inspector and comparing nodes when the
'object' element is loading a valid external SVG document, and when I am
appending the child representing the SVG document created by the DOM
functions.
However the child node (#document) does not specify 'svg' as the root
element, but instead 'HTML'. Something is not working.
Here is the relevant code in 'ScriptTest.html' which is the HTML in which
the SVG is supposed to be embedded. Below it is the relevant code for
'svglib.js' which is supposed to contain code for building the SVG
dynamically.
What this code is supposed to do is load the HTML page and execute the
anonymous script, and draw a navy blue-bordered yellow rectangle on a
blank page. This is similar to the example in the SVG 1.1 W3C
Recommendation on page 202 of the 719-page PDF.
I am getting an exception when embedSVG object placeInHTML() method is
called: NS_ERROR_DOM_HIERARCHY_REQUEST_ERR. I find in DOM Inspector in
spite of or after the exception that a document is placed as a child of
the object element, but it is HTML, with a default 'head', 'title',
'body' elements placed.
Where am I blowing it?
Determine what the previous page was that the user was viewing, even if the user arrived at my site by through the use of a browser function (history, location bar, refresh, etc.). Is this possible?
I'm not wuite sure how document.history functions - what degree of privacy is given to the user and to what extent can web pages get URLs from the user's history?
I am trying to make a function run if the mouse is moved over the document but when using the object onmousemove it seems to run the code even if the mouse is still over then document, how can I make it so if the mouse is over the document but isn't moving then don't run the code but once the mouse moves run the code? This is the code I made to handle the mouse move collections.
[Code]..
But with this code it runs even when the user doesn't move their mouse and the notification box pops up every second as the code seems to think a still mouse is a moving mouse.
I was thinking about having a run once system but that would mean if the mouse moves it runs once and then if the mouse moves again the code will not run as it has already ran before.
I want to switch a big function from a document.onkeydown = function to a document.onkeypress = function, or vice versa depeding on the type of browser.
However it is quite a big function so it's pretty much out of the question to have it appear in full twice.
Any ideas how to change the target event (onkeydown/onkeypress) without writing the whole function twice?
I am working on creating a document where you check a bunch of checkboxes to select what to include, then click on a button. A function then opens a new window and writes the HTML code to run scripts in .js files to populate the page. Code:
View 4 Replies View RelatedI have been searching for a way to trap changes done to the document object (mainly by the function document.write();).
Example of code that doesn't work:
function myFunction() {
ed.document.onchange = doFunction(document.body.innerHTML);
ed.document.open();
ed.document.write('Hello');
ed.document.close();
}
function do_function(body) {
alert(body);
}
It only fires when the page loads, not when I change the text. You are free to use any event that works, but i think onchange was the one to fit this problem. The alert will write the initialpage, but will never write the tekst 'Hello' that is the new change.
Any javagurus out there know a solution to pick up any fired events triggered by document.write();
I am trying to write a bunch of text onto a new document using document.write() and somehow need to format it to include line breaks.
For example:
Code JavaScript:
document.write(Line 1);
document.write(Line 2);
I have tried including and it does not work. I have also tried document.writeln() and that also does not work. From what I have found on the Internet, one (if not both) of those methods should have worked.
I have created a servlet that does nothing more than create a XML file.i have got some JQuery code that reloads the servlet to get the XML data.This works fine and i am able to load the data i want, the problem i have is that when the data is loaded to the jsp page it displays [object Document] in front of my output.
Code JavaScript:
$(document).ready(function() {
setInterval(function() {[code]....
XML file only has one value, called row 1 with the data, "wow this is cool", but my output is: [object Document]
does anyone know of any javascript method that does the same job as
document.write(), but not necessarily at the end of the document? For
instance, insert some text inside an element that has a specific ID
tag?
sometimes document.write doesn't work for me but document.writeln always does..
View 3 Replies View RelatedI have three files:
HTML file (default.htm)
Code:
<body>
THE QUICK BROWN FOX JUMPED OVER THE LAZY OLD DOG
<script type="text/javascript" src="testing.js"></script>
[Code]....
When I run the above files the original text on default.htm is wiped and replaced by the document.writeln text in test2.js. What I wanted to happen was for this text to be added to the default.htm page (and not wipe what was already there). I believe this is because the htm file has already parsed.
I know people say you should use innerHTML and not document.write or document.writeln. Unfortunately, I have no control over the contents of the first file (default.htm) or the third file (test2.js) but the content in test2.js will always be in either document.write or document.writeln format. So I cannot use innerHTML.
My problem is how can I (from within the second file, testing.js) ensure that the page is not parsed before the third file has finished.
I need to eliminate the document.write for this bit of code
copyright=new Date();
update=copyright.getFullYear();
document.write("Copyright © 2001-"+ update + " " );
var showtext = "Tecknetix";
var mailpart1 = "webmaster";
var mailpart2 = "tecknetix.com";
document.write("<a title='email tecknetix' class='hov' href=" + "mail" + "to:" + mailpart1 + "@" + mailpart2 + ">" + showtext + "</a><br />");
The reason is now I'm using <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" /> with xhmtl 1.1
Since I've changed the MIME type to application/xhtml+xml from text/html the document.write is invalid now.
Here is a page with a demo on it so you can see how they changed document.write("<link rel="stylesheet" ...") around.
http://www.xml.com/lpt/a/2003/03/19/dive-into-xml.html
I think only the Moz1.4 supports application/xhtml+xml
You can see it on my 4 page site. http://www.tecknetix.com/
In IE6 you can read the copyright notice but in Mozilla you can't. But in you go to view > page info in Moz - you can see application/xhtml+xml as the type.
I'm learning JavaScript, and I have learned very much of the language. But I don't know what the difference between document.write and document.writeln is.
Can somebody tell me the difference?
Which is the better option to use when dynamically loading a page?
document.location.href = "newpage.html"
or
document.URL = "newpage.html"
My book says that Netscape depreciated document.location.href in favour of document.URL, but yahoo are using document.location.href. Also, is there a good online reference (up-to-date) of the DOM which includes stuff like this?
What is the jquery equivalent of document.body.scrollTop / document.documentElement.scrollTop
View 11 Replies View RelatedIt's possible to style document.body not to start at 0,0 for example: body {width: 1000px; margin-left: auto; margin-right: auto;} This means that X/Y of the body is not 0,0 but how can I find out what the position is using javascript? document.body.offsetLeft; is 0 and offsetParent is null yet if I position something absolutely at 0,0 it goes to 0,0 of the window, not the body!
View 2 Replies View RelatedAs I understand it, document.layers only works in Netscape 4+ (ie. it
doesn't work in any version of Internet Explorer), while document.all
only works in Internet Explorer 4+ (ie. it doesn't work in any version
of Netscape). Is that correct?
Also, what about document.getElementById? When did Internet Explorer
start supporting that and when did Netscape start supporting that?
I ask because I'm wondering how necessary doing something similar to
the following is:
if(document.getElementById)
obj = document.getElementById(id);
else if(document.all)
obj = document.all[id];
else if(document.layers)
obj = document.layers[id];
else
return 1;
im having trouble getting through all of this if statement block in firefox. the internet explorer code works. here is the firefox version first:
function disbleTextButton(_varButtonId, _varNewText) {
if(browserType() == "Netscape"){
for (i = 0; i < document.updateForm.getElementsByTagName('*').length; i++) {
obj = document.updateForm.elements[i];
if (obj.tagName == "INPUT") {
if (obj.type == "image") {
if (obj.name == _varButtonId) {
alert(obj.src);
break;
} } } }
}
i want to get to the alert but cant. the IE explorer code works perfectly. here it is.
for (i = 0; i < document.updateForm.all.length; i++) {
obj = document.updateForm.all[i];
if (obj.tagName == "INPUT") {
if (obj.type == "image") {
if (obj.name == _varButtonId) {
alert(obj.src);
break;
} } }}