javascript regex - javascript

I just had a question about the regex object in javascript...
My regex is this:
data-href="[^"\r\n]*"
when I use it in this site:
http://www.regular-expressions.info/javascriptexample.html
matching against the following string:
<div class="fb-like" data-href="http://example.org" data-send="true" data-layout="box_count"
it tests positive and returns the url. My goal is to dynamically change the value of data-href parameter for the div using javascript to dynamically include the anchors of the webpage (the site Im working on uses an ajax based navigation dependent on # anchors in the url).... And i really want the facebook button to be mutable so that when a person clicks "like", they dont just "like" the homepage.
how would I do that?
I tried various tutorials but couldn't get the regex to match at all (it always returned false).
where should I start?
thx!!!

You can change the attribute using jQuery or any other JS-Framework. Then you don't need any regex. This
$(".fb-like").attr("data-href", window.location.href);
should do it.

as it turns out the facebook button doesn't actually use the data-href attribute to specify the link it is going to use for its integration. My complete and fundamental misunderstanding.
Looks like it figures that out independently using a referrer or figures out what domain its script is running from... anyway, sorry about the hassle.

Related

How to use i18next to localise my website?

I have a very simple website with no backend, just pure html pages.
I need to have English/Chinese versions for this website, what I need to achieve is have a button on NavBar, when users click this button, the wording on entire website will be changed to Chinese/English.
All the examples I have seen that they are all require something like this:
localize(".nav");
So does it mean that I need to do something like this:
localize("body");
in order to get the whole website language switched?
According to the doc here is the list of supported-frameworks. As your project is a basic HTML one you should use this https://github.com/mthh/loc-i18next. When you init the module on a TAG you should me make sure there is the data-i18n="myKey" attribute with the key of string that need to be translated. So localize("body"); should translate the whole body but you must add the data-i18n attribute to each tag with a string key

How to repeat text from one page to another to reduce time in updating every month

I've been looking everywhere and I can't seem to find exactly what I'm looking for, I'm starting to think I should be looking at some kind of Javascript?
Basically, I have an amount £1,000,000 displayed over an image button and I need this repeated on a different page (The page the button leads to).
As I've never done this before I'm not sure where to look or what I need to be looking at as I'm a novice in this area.
Any help would be appreciated.
If the value is static so you can use content css property :
https://developer.mozilla.org/fr/docs/Web/CSS/content
If the amount is dynamic you should pass variable through Url or via form.
As I don't have a clue as to what you're setup is, i'll make some assumptions:
a static HTML site
no javascript frameworks (so no jQuery or jqLite etc)
with these assumptions you should start by looking up url attributes as a way to communicate basic information between pages.
As an example, the button href should look something like this:
/link-to-page?amount=1000000
then you grab the amount on the new page - with javascript - looking in the window.location object
This is a good resource

How to linkify the URL in a text?

I am using Html, Jquery and Javascript. I am using linkify javascript library and is working fine. But if there is no space before the URL then it does not work. How to solve this? I have below URL along with text.
Please click the linkhttp://www.asdfgh.com
Please see there is no space before the URL. How to linkify the URL here?Can it be done using Javascript?
don't Know linkify. Maybe there is an option for setting individual patterns.
Otherways you could search the text for this string and replace it, before linkify do its work. But its dirty.
yourtext=yourtext.replace("linkhttp://","link http://");

on click href, how to create new html page and write html dynamic in to page using jQuery?

I am trying to implement web application for sales. So in that i would like to generate dynamic html pages on fly by clicking on a product.
<a href="/products/34567.html">
<img src="leather1.png" alt="Leather Bag" width="82" height="82">
</a>
when i click on leather1.png , i should redirect to 34567.html.
But 34567 html page will not be present in my source. On click image i want to create new html page naming 34567.html and write html content in to the page using jQuery.
Can any one help me on how to approach to achieve this..
Your immediate response is highly appreciated!
Thanks.
i think you arelooking for this:
check out this paper: http://www.htmlgoodies.com/beyond/javascript/article.php/3776371
goodluck!
Based on your comments, what you want is an AJAX call. You'd want to have an onclick action on the anchors that would trigger an AJAX request, with a callback that knew how to render the result - it could replace the document object's html. Then for useability the action should probably display a loading screen. Finally, the action should return false so the link isn't followed.
Key point: if an onclick operation on an anchor tag returns false, the link is not followed by the browser.
I would hasten to add though, having the href of a link simply not work is a bit of an anti-pattern. Your HTML is telling the browser there's a related document at /products/34567.html ... SEO will not find your product 'pages'. AJAX is all well and dandy, but this isn't the best use of it. best if that link really worked, and the AJAX was just an optional step. Web crawlers don't usually run JS and won't find your products - and if you want them to sell, you want google to find them!
Hope that makes sense!

Html/Javascript - How to make an html link display a url, and have it actually be redirected to a javascript function?

I have an html page, and I need a link to show that the user would be going to 'example.html', when really, the link goes to 'javascipt:ajaxLoad(example.html);'.
I tried this:
Example
But it didn't work. Any help? I already asked the webmasters stackexchange, and they told me that this would be a javascript programming question. Not an html question.
Example
By returning false you prevent the default action. And this way the links will still work when javascript is disabled, but then you don't get the AJAX functionality.
Just point the href at the actual file. The javascript onclick will take precedence - as long as you take care to disable the actual click effect by doing a "return false" or similar, the status bar will show 'example.html' and not the javascript url.
As well, note that it should be javascript:... (you're missing an r). The onwhatever attributes are already assumed to be javascript, so you could just say onclick="ajaxLoad(...) anyways.
Look, I'm not sure if I got exactly what you're asking about here, but the following fix often works with me. Just change the double-quotes to single-quotes, and put double-quotes around the example.html part
<a href="example" onclick='javascipt:ajaxLoad("example.html");'>Example</a>

Categories

Resources