Is there any way how to remove (anonymise - just place some empty string instead of url) all links in document?
A tags, and some javascripts actions which can open new url.
I have html in document and I am using nodejs, I can use puppeteer or some dom tool.
With javascript you can do this:
var anchors = document.getElementsByTagName('a');
for (var anchor of anchors) {
anchor.href = 'javascript:void(0)';
}
I've read that 'javascript:void(0)' is the best substitute.
Related
I'm trying to send transaction emails from my website using the MailKit library but I can't make the html render an anchor tag. In fact I'm not sure that any of the html is being rendered. Any ideas what's wrong? My code is below.
var message = new MimeMessage();
message.From.Add(new MailboxAddress("Eternal Meta", "eternal.meta.transactions#gmail.com"));
message.To.Add(new MailboxAddress(user.Username, user.Email));
message.Subject = "Eternal Meta - Registration";
var builder = new BodyBuilder();
builder.HtmlBody = "<p>Use the link below to activate your account</p><br>Click Me";
message.Body = builder.ToMessageBody();
using (var client = new SmtpClient())
{
client.Connect("smtp.gmail.com", 587, false);
client.Authenticate("eternal.meta.transactions#gmail.com", "password");
client.Send(message);
client.Disconnect(true);
}
Use a fully qualified URL for the "href" attribute (like https://[...]).
The mail client can parse the HTML inside your message and most probably the "href" attribute gets removed as the URL is considered relative.
I am using a template tag in a webkit browser (JavaFX WebView 2.2) to store elements that I may clone and append on the main part of the document.
However, I can't access its content using templateElement.content (the HTML5 standard). Instead, I use jQuery to get the elements inside the template TAG with the selector "#templateElement div".
Seems the template tag is not yet fully supported (inner scripts also run), although its contents are not rendered.
My fear is that, when the template tag becomes supported, the way to get its contents will break and my page will stop working.
What is the recommended way of getting template contents regardless future implementation changes?
HTML:
<template id="templateElement">
<div>Clone Me!</div>
</template>
JavaScript:
function getContentsCurrent() {
var toBeCloned = $("#templateElement div")[0];
//append where needed...
}
function getContentsFuture() {
var toBeCloned = templateElement.content.getElementsByTagName("div")[0];
//append where needed...
}
EDIT
I think jQuery won't be able to handle this automatically, even in the future, because the template "innerHTML" is purposely routed to content so that it becomes inaccessible to the DOM (so no selector touches it accidentally).
You could test if the content feature exists before:
function getContents() {
var toBeCloned;
if ( templateElement.content )
toBeCloned = templateElement.content.getElementsByTagName("div")[0];
else
toBeCloned = templateElement.querySelector("div");
//append where needed...
}
Another way:
var content = templateElement.content || templateElement
var toBeCloned = content.querySelector( "div" )
//...
HTML has a draft specification for a < template > tag. Details here: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template
I'm thinking about using Rivets.JS on a new project, I also want to use this new template tag.
Can the two be made to work together nicely?
I imagine I'd want to tell rivets something along the lines of 'get this template, bind it to this data and output the result here'.
You can copy the template as your normally would, and then use Rivets to bind to your new element. demo # jsfiddle
HTML:
<template id="demo">
<p id="tag">{ demo.info }<p>
</template>
Javascript:
var demo = {
info: "Test string"
}
// Copy template data to visible DOM
var el = document.getElementById("demo");
var clone = document.importNode(el.content, true);
document.body.appendChild(clone);
// Bind using Rivets as normal
var tag = document.getElementById("tag");
rivets.bind(tag, { demo: demo });
I'm trying to navigate within a webpage that has been loaded from a remote server in my WebView control (Cocoa application). I would like to navigate to a particular tag that i can see in the HTML code of that page. The purpose of this all is to show the part of the HTML page that is of my interest at the top of the WebView control.
I know that in HTML code you can navigate by using something like #MIDDLE, #TOP etc. However, is this possible to do from outside of the HTML code using the WebView API?
Thanks for your reply in advance!
I found the answer to my question with the help of an other question (How to scroll HTML page to given anchor using jQuery or Javascript?).
The piece of code below does the trick for me. It searches for HTML elements with attribute: class = "container" in the HTML data that is loaded in the WebView component self.webView.
-(void) scrollMyImportantHTMLPartInView
{
// Get a list of HTML elements that contain attribute class = "container" (eg. <div class "container">)
DOMNodeList *nodeList = [[[self.webView mainFrame] DOMDocument] getElementsByClassName: #"container"];
if( nodeList && nodeList.length >= 1 ) {
// get the first node (class = "container") from the list
DOMNode *domNode = [nodeList item:0];
// Make sure it's a DOM element type
if( domNode.nodeType == DOM_ELEMENT_NODE ) {
// It's now save to cast from DOMNode* to DOMElement*
DOMElement* domElement = (DOMElement*) domNode;
// Scroll begining of HTML node into view
[domElement scrollIntoView: YES];
}
}
}
I have frames setup on a page, is there a way to force all links in a child frame to open in a new window('blank') rather than 'self'?
I have no access to the page that I have in my frame, sometimes the links open new pages sometimes they just transfer to a totally new page. I want to keep some consistency by making all links open in new pages.
You could use some javascript:
var links = document.getElementsByTagName('a');
for (var i = 0, l = links.length; i < l; ++i) {
links[i].target = '_blank';
}
You'll just have to get a reference to the document in your frame (sorry, it's been a long time since I've worked with frames). From memory it's something easy like frame.document
I'm not positive that you can modify the DOM of external pages, but it's worth a shot.
var links = document.getElementsByTagName('a');
for (var i = 0, l = links.length; i < l; ++i) {
links[i].target = '_blank';
}
This will not work for Frames loaded by Javascript to open in a new Window :(
Don't use frames.
Or load them in using a HTTP object (there's plenty in a lot of server-side languages), modify the links using regular expressions to point to '_blank' instead' and then put them on your page.
Alternatively, you might be able to use the DOM:
nodeLink = document.getElementById("alink");
nodeLink.setAttribute("target", "_blank");
What am I missing when I respond with the following?
If you can't change the page in the frame, you're not going to change its behavior.
Put this between your <head> and </head> tags:
<base target="_blank">
Just replace _blank with whatever target you want to be the base for all links on the page.
Source: http://www.w3schools.com/tags/att_base_target.asp