Javascript link to bookmarklet not working - javascript

I've made a simple bookmarklet, to aid with the reading of Daring Fireball.
http://saltcod.github.com/Snowball/
My issue is that the Drag Me Up, Scottie! link doesn't work when you drag it up. If you manually create the bookmark with the same code (https://raw.github.com/saltcod/Snowball/master/snowball.js) it will work, but it won't work if you try and drag it up.
The link is breaking the block of Javascript somehow. Anyone got any ideas as to what I might do with it?

You messed up the quotation marks; your page is NOT valid HTML.
Inside a link, you cannot use ", but either use ' or encode the quotation marks.
Did you not notice that your javascript link was truncated at the first "?

Related

How do i become href out of a link

Following problem:
I would like to not have to copy my navigation bar over every site. So I wrote it in an extra Document and included it with php. The site ur on has a special class to show its active now that where I'm stuck at. I tried following statement just to see if my idea works
<script> if(document.getElementById("test").href == window.location.pathname){window.alert("wow");}
Spoiler alert it does not:(
I know that the pathname is the same as href(tried it) but I can't get the href like that. Does anybody know how to do that? Sorry for my English
Thanks a lot for helping
PS: I'm just getting into js I usually work with other languages but wanted to get into website design.
The problem was simple : document.getElementById("test").href gives out the whole link with www even thoug its not standing in there while window.location.pathname just gives out the path like /index.php. I had to use window.location.href instead.
Thanks for all the answers

Button as a fake link for a Google Analytics funnel

I'm trying to set up a funnel that has a final step of clicking on a button and downloading a document. Since I can't track the button, I was hoping to set up a fake link that doesn't redirect the user anywhere but allows Google Analytics to see how many people clicked on the button.
What I have is this Javascript piece of code but when it gives me an error:
<a href=”/goal/example” onclick=”javascript:pageTracker._trackPageview (‘example’);”target=”blank”>
Or, if this doesn't work at all, is there any other way to add a button to my funnel?
Thanks!
To piggy-back on #nyuen's answer, (though without your error message it's hard to know what's wrong), it looks like your link could be improved as well. First, since it sounds like you'd rather it not link anywhere, I'd set the href to your code rather than the onclick. And second, if you don't want it leading anywhere a target="blank" is going to be annoying. (Also I assume your <a> is closed eventually). Try:
[...]
There's a couple things wrong with the code looks like. Try this:
onclick="_gaq.push(['_trackPageview', 'example'])"
The javascript part is optional, and also the quotes need to be straight quotes, not the 'smart' quotes.

prevent html special characters

I am trying to deploy my bookmarklet in public, but I am not sure what is the best way to do it. Suppose I have,
javascript:(function(){console.log("hello");}())
And I make it draggable to the bookmarklet by enclosing it within a href tag. The trouble is that HTML special characters are encoded like %07d for the above snippet. What's the conventional way to solve this problem?
Thank you!
It should work fine, till it is in the following format.
Bookmarklet
Note: I changed console.log() to alert() to make the result view able immediately.
Live Demo: http://jsfiddle.net/qyL4L/

make addClass reset on click

I'm sure it's just changing one thing, or adding it, but I can't make it work. An image on top of a video slider is supposed to fade away when you play the video. Then, if you click another (they're linked through thumbnails) it will make the image pop back up and fade agisn. the first part works, but after the first time, it doesn't work anymore. Can anyone help me? Here's the fiddle
You have a few serious html and javascript syntax errors that might be causing some trouble.
I properly indented your code in jsfiddle and seems like you have a broken body tag, and two extra closing div tags that are disconnected.
In your javascript, in the videos array, you missed a pretty important quote.
Check this fiddle http://jsfiddle.net/elclanrs/dp5wJ/12/. When the code is properly indented the erors are very easy to spot with the syntax highlighting.
You're re-binding $('#myVid').bind("ended",... on each click.

HTML Formatter in Javascript

I have been looking around for a HTML formatter to incorporate with a project I am doing. I need it to be written in Javascript since I want the formatting done on the client side.
The problem is, the few that I have tried don't work very well... For example:
http://www.davidpirek.com/blog/html-beautifier-jquery-plugin : Has a problem with one of the For loops (in the cleanAsync function). Chrome says "unexpected token ILLEGAL"
JS Beautifier on GitHub : When I have links in the HTML it will put a newline character after it. The problem is, I have a period directly after the link in some cases and it will add a space between the link text and the period in the sentence. I tried poking around to fix it but I could not.
Are there any others, or does anyone have recommendations to fix the above two?
EDIT:
This is for editing code, so I just need something to tab in the lines, etc. The code output will go in a textarea.
A few to look at, all have working demos:
http://alexgorbatchev.com/SyntaxHighlighter/
http://shjs.sourceforge.net/
http://jush.sourceforge.net/
http://dojotoolkit.org/reference-guide/dojox/highlight.html
use https://github.com/beautify-web/js-beautify and pass your code to html_beautify() method.

Categories