Get Selection Position By Js And Make Sure Code Work For All Browsers?
Feb 15, 2012
I need to get the selection position by js and make sure that this code work for all the browsers.
For example, the user selected this text (red text is selected):
Hello world
The function should return to me array or two values wich they are: 3,9 (start and end position of the selection)
Then you create the text you want to change colour in a paragraph with id "text":
<p id="text"> Here is where you type your text. </p>
This works beautifully in IE and Opera, but does absolutely nothing in Mozilla-based browsers. Can I do anything to this script to make it work in Mozilla browsers?
I recently made a simple tool that opens a website in an iFrame and tells the user how long the page took to load. I made it out of a premade stopwatch
When i run the test in most browsers (Chrome, Firefox 3.6 and older, IE) it works fine with the output textbox going from "Please run the test" to "Test Running" to [TIME TAKEN FOR PAGE TO LOAD] but in firefox 3.7 (Minefield) it goes from "Please run the test" to "0" every time and the page in the iFrame doesn't load.
I've read that Firefox 3.7 has a new Javascript Engine
The test is at [URL] and the problem code is on THIS PAGE (Use View Source in your browser)
how to make the following code work for both IE and Mozilla?
function AddRow() { if (navigator.appName=="Microsoft Internet Explorer")
[code]...
//the following javascript function is saved in another .js file which is then called from the main php file when the above button is clicked. It works fine with Mozilla and Chrome.
function AddRow() { var morerow=document.getElementById("tbl")
[code]...
Also, why are you mixing DOM standard with innerHTML?
I have made a website that you need a password to get into. The following javascript code works in Internet Explorer but, I need it to work in Safari also. Can anyone please rewrite this code, as simple as possible, to work in both Safari and Internet Explorer?
im trying to make the left Product Categories background position "rollover" menu work on this page: [URL] at the moment the page loads and CSS hover works to set the background position so that the graphic behind makes a roll over effect. i put some javascript to set the background position permantly to the roll over on click (so the user can see which one they are on) but then this knocks out the roll over effect on all other categories - it knocks out the CSS hover: onclick="setStyle('c1','backgroundPosition','0px 0px');
it means that c1:hover no longer works.. i tried putting !important in the CSS c1:hover background position and this fixed it in Firefox but not IE. So how can i write something in Javascript to also say: onclick="setStyle('c1:hover','backgroundPosition','-276px 0px');
i know Javascript does not do hyphens and the way to get for example "background-position" in CSS is to ditch the hyphen and make "P"osition capitol. perhaps something can be done also to get to the CSS hover attribute?
I'm trying to apply the "absolute" position to the DOM object for non-IE browsers but Mozilla (or Firefox) does not recognize it. But the top and left position works for the "div" tag though. The IE browser works fine though.[code]...
My intension is, to create my own WYSIWYG Editor with own tags. I am doing this with contenteditable elements. If the user is selecting Text and clicks a button (For Example B) the selected Range should be wrapped in "<strong>|</strong>". To program this I need to know the start and the end of the users selection. But the textrange object and the regular rangeobject are not helping me with this issue.
For Example my text would be:
Lets say the user selected 'name is David'. What I do need now is the position in the document where the selection starts.
In this case I would need 27 as my result, because the number of digits would be:
How to do this with Javascript? It must be possible, because TinyMCE, Aloha etc are working WYSIWYG Editors and they must have figured this out.
I already know execCommand and pasteHTML, but these methods are no alternative for me, because they just create what they want and the code looks different in every browser.
I'm really struggling to find any sample code for getting the start and end position of a text area selection (i.e. a textarea contains the phrase "Why isn't there a standard, well-known function that does this?" and somebody selects the word "there" -- using a function, I'd like to be able to grab the start position and end position of the word "there").
Can anybody help me with this, or am I going to have to hack together some long-winded function to do this seemingly simple task?
I'm looking for a function that I can use which will do the following when the mouse cursor is in a textarea:
know which textarea to work with based on current cursor position (not sure if this possible, couldn't find examples) - i.e. just 1 'Bold' button to operate on multiple textareas.
insert tag or tags (i.e. ,[image]) at cursor position, if text is selected then insert tags around text selection.
I am trying to set up some code to control a mouseover popup image. I have the script that works except in certain browsers the results are different.This is the page: (just mouse over the first players name).Here is the script:
<script type="text/javascript"> function ShowPopup(hoveritem) {
Q: I have a pretty big html page - about 1,500 lines of code, 1,000 of which is javascript. (It's also referencing other javascript code, perhaps another 2,000 lines or so).
When I boot up the page in a fresh browser, it invariably crashes; the page just hangs. But, after killing the browser, and opening it up in a new one, the page seems to run fine. Is there some sort of javascript code limit that a web page / browser can handle...? Anyone know if there's a way to get around this? [Did I misread the problem? I'm pretty sure my code is fine.] Code:
How can I write javascript codes to interact with a smart card reader? I have found some activex controls and examples, but I think, it will be limited to IE only.How can I make it run in all browsers, if the card reader driver is installed, and the hardware is available for use?My problem is to make sure that the user puts his/her own smart card in the reader unit before he signs up in a website (a particular website, that I will be coding for).
I'm trying to get sounds to play on image mouseovers using dreamweaver 8, and I found out that the code it generates to do this only works for IE. Is there a way to do this so that it will work with most of the popular browsers? I don't care if it can be done with dreamweaver or if I have to hand code or copy code from somewhere, I just want it to work.
Here is what DW creates:
function MM_controlSound(x, _sndObj, sndFile) { //v3.0 var i, method = "", sndObj = eval(_sndObj); if (sndObj != null) { if (navigator.appName == 'Netscape') method = "play"; else { if (window.MM_WMP == null) { window.MM_WMP = false; for(i in sndObj) if (i == "ActiveMovie") { window.MM_WMP = true; break; } } if (window.MM_WMP) method = "play"; else if (sndObj.FileName) method = "run"; } } if (method) eval(_sndObj+"."+method+"()"); else window.location = sndFile; }
I have some attributes that aren't really standard attributes:
e.g.
<option additional="34">Deep Purple</option>
That "additional" attribute is an attribute that I use with Jquery to add an additional price to the item.How many browsers will work with custom attributes like that? Or will I have to use a standard attribute (Note: if I use Value it overwrites the value inside of the option).
Is there such a thing as a dropdown menu that works in all browsers? (or at least all the commonly used ones)... Is JavaScript a good way to go? and if yes, are there any precoded templates available that are fairly straightforward to integrate and adapt for dropdowns?
After using and altering a javascript random image generator code from the web, I've got it doing exactly what I wanted...but only on the mac.The page is supposed to display 5 random images next to each other.Mac Opera shows 3 of 5 images.IE 8 on the PC does the same as Mac Opera, displaying images from gallery[0], gallery[2] and gallery[4].
Between the gallery[0] and gallery[2] images, the page displays: pickImageFrom(1); Between the gallery[2] and gallery[4] images, the page displays: pickImageFrom(3);[code].....
I am having difficulty getting the cursor to turn into a magnifier in both Mozilla and Webkit browsers. In the js file, I have this line
Code:
cursorcss: 'url(magnify.cur), -moz-zoom-in', //Value for CSS's 'cursor' attribute, added to original image which works fine with Firefox, however if I do this, neither of them work.
I have the following function that display a list depending on the drop down option the user selects but doesnt not work on explorer it works on other browsers but on exploere i get the following error code...
<input type="reset" name="cancel" value="Cancel" onclick="javascript:window.location.href('/index.php');" /> In IE5.5 clicking the cancel button loads the index.php page fine. In Firefox 1.0 & also the version of IE running on my IPAQ it doesn't work - clicking the button doesn't do anything.
Anyone have any ideas or alternative solutions? I thought maybe I was using an IE only thing but it is a version of IE on the IPAQ. I thought maybe it was not standards compliant but I haven't found anyone having a similar problem.
Any idea or advice? TIA, BG.
PS Ignore that I am using a reset button to do this - I have also tried it in the body tag like this:
Code:
<body onload="javascript:alert('Login Successfull! You are logged into my app');window.location.href('/myapp/index.php');">
First, We 've a course registeration Web app that was developed in .NET/javascript.
In brief, the students login, then the available courses is drawn to him (as DIVs) to select courses then apply registeration.
Of course , the dynamic part of selecting/highliting courses is done in javascript as a clientside Javascript.
The problem that this app was developed with no x-browser compatibility in mind (e.g firefox and chrome). it works fine on IE , ofcourse doesn't work properly on Mozilla browsers.
Now, i want to modify it to be mozilla compatible , i spent time inspecting it (functions and classes, "yes the developer made a javascript classes") .
Is there a tool or something that porting to mozilla ?