I have a problem making easy user interaction with content, displayed with UIWebView. I want to avoid any userInteraction with it, but make some actions programmatically. When user tapped on the some place of the UIWebView I want to find the nearest word. Furthermore I want to know its rect. Is there any js functions, which will help me?
Take a look at this question. The code that is quoted both in question and answers should be a good start.
Related
I want to create a bookmarklet that I can drop on my browser's bookmark toolbar which, when clicked, inserts a fixed, predefined text (in my use case, a shruggie: ¯\_(ツ)_/¯ ) at the current cursor position (assuming that the cursor is in an editable input field or textarea). However, I am a beginner at JavaScript, and can't figure out how to get started doing this. Any help? If I can get a pointer in the right direction, I can probably figure it out from there. Thanks!
Apologies for the delay; life threw a few curveballs at me right about the time I posted the question, and I forgot about this until StackOverflow notified me of the responses tonight.
The comment by afuous gave me everything I was looking for, and I now have a working bookmarklet. For anyone else who comes across this, here it is:
javascript:(function(a){a.value=a.value.slice(0,a.selectionStart)+"%C2%AF\\_(%E3%83%84)_/%C2%AF"+a.value.slice(a.selectionEnd);})(document.activeElement);
Or, as JavaScript that hasn't been converted to bookmarklet form:
(function (a) {
a.value =
a.value.slice(0, a.selectionStart) +
"¯\\_(ツ)_/¯" +
a.value.slice(a.selectionEnd);
})(document.activeElement);
This has the benefit of allowing for me to select a portion of a text and use the bookmarklet to replace the selection with a shruggie, as if I had hit a hypothetical shruggie key on the keyboard.
Feel free to steal and modify as you see fit. This has been tested only in Firefox 50.0.2, but I think it should work in all modern browsers. (It won't work in Internet Explorer 8 or earlier.)
CSS Tricks has an article that explains how to do that and more. I'm well aware link only answers are less than ideal here, however the question is asking for pointers in the right direction, so I believe its a good fit.
The bookmarklet from the tutorial prefills forms, so essentially you are going to want to gut it, but first peek into how it is finding form controls and prefilling them. Then tweak to fit your desired functionality, and finally rip everything else out that you do not need or use.
Prefilling Forms Custom Bookmarklet
A friend of mine asked me if it is possible to "make something" to avoid someone stealing her photos from her blog posts. I told her that we can try some options but at the end there's always a way to get the pictures, and that some people even take screen shots so they can have the images.
Then I asked myself if the screen capture exists as an event so you can catch it using js/jQuery and hide the image. I have searched for a while now but still can't find an answer.
Is this possible?
Find out in the ASCII table which is the screenshot key on the keyboard, capture it via javascript and return false.
That is a way to do it, but in the end, there is always a way to bypass that. There is even software to take those screenshots.
For example on windows 8, if you press the Windows key plus the print screen, it will automatically save the screenshot on a folder inside your pictures folder.
It's pretty much a lost battle.
No, it's not possible because a screen capture event belongs to the OS, not to the browser so JavaScript wouldn't be aware of it. What you could be able to do is detect the key strokes associated to the screen capture and hiding the image if it happens.
It's still trivial, because anyone could take a picture to the monitor screen.
As the other answered, it's pretty impossible to avoid that: if something is on a computer's screen, then it is on that computer, somehow. At last, you can always take a screnshot of the screen.
The only solution, if possible, would be to use a watermark.
Using Javascript, I need to allow a user to double click a word on a page and retrieve the sentence that it appears in. Not just any sentence, but that specific one. I've toyed with retrieving all sentences that that word appears in and somehow choosing the correct sentence, so maybe that's an option.
I've scoured the web looking for this beast, and I've thought a lot about it. Some have recommended using Rangy but I haven't been able to find the functionality I'm looking for, or even functionality that would help me get where I need to be.
Any ideas?
You could turn your page into one or multiple read-only textareas, use clever CSS styling to mask it, then use the onselect event as described here: Detect selected text in a text area with javascript
Depends of course, how your page looks like and where it's used.
Before I started to try and make this thing, I wanted to know if it is possible, under the following circumstances:
The code to script up that math must be able to be taken, submitted and stored in a database
The code for two pieces of math which look exactly the same must have the exact same code
According to the requirements, wherever the user clicks his or her mouse, the caret must move to that specific element or part of the math
So, is it possible? I'm looking forward to using technologies such as HTML, JavaScript, jQuery, and even Flash as a last resort.
MathQuill lets you type maths in a WYSIWYG fashion, source here.
There is a demo on the homepage.
I think you want something like MathML. Take a look here. http://www.w3.org/Math/
or maybe http://code.google.com/p/mathmleditor/
I found this a while ago http://www.codecogs.com/latex/eqneditor.php pretty useful implementation of LaTeX with a live preview, I've used it a few times. Probably doesn't fit the bill for your point 3 either but just in case it is useful.
I have a standard html based textarea. That I want to go over the entered text as someone enters it looking for keywords or phrases. So I can catch them if typed and trigger an event accordingly. In this example I want to wrap the particular keywords or phrases in a bracket kind of like bbcode. My issue is I am Some keywords and or phrases are similar, so I don't want the action to fire off multiple times or at the wrong time. Right now the closest thing I can think of thats remotely similar to this is Facebook when you start typing someones name in the status box. There name kind of does an auto complete like thing. This is something I eventually want to expand this out towards but for now I am happy with just catching the keywords and or phrases accordingly and triggering the series of events I want to happen when they are found.
Trying to find a starting point for this. Also I need to fire off another event if the text is removed from the string that is the textarea. Which I think I can rebase off the inital concept I am looking for here.
Now I know what some may think I am not looking for an end solution (unless you have one and want to offer it up). I am mostly looking for logic points in how to approach this from start to finish. But all in all I am just trying to figure out how to specifically iterate over the textarea to find keywords and phrases specifically. I figure everytime someone hits the space key I can have it fire off an event to scan if you will the enter textarea. But doing the scan is the part the confusing part at the moment.
The phrases and keywords are stored in an array also.