Is it possible to target anchor link via JS entered into href? I need to kill the cursor style on a SPECIFIC link. I cannot do it any other way - so no css, jQuery, etc. It has to go into a CMS via an insert js link on a link.
Example of input: javascript:void(0);targetThisLink.style.cursor='default'
Example of output inserted into the page/DOM: Link
I tried this.style.cursor='default'. It failed. I am not sure this is possible, but if it is let me know.
Try this
Link
Note two things:
Style is only applied after user clicks on the link
You have to have a way to target that specific link via querySelector. Class or ID would be ideal. I used a tag but that would apply same style to all other links on the page. If nothing else possible try using a[href^=javascript:]
Are you able to use mouseover in your CMS?
See example below:
Click Me
Related
Is it possible to insert a button element
(<button type= "submit">)
into the html code of the page using the driver.execute_script method?
And how to specify its location?
For example, there is a text field email (driver.find_element_by_xpath ("//input[#name= 'email']") and I need to insert the submit button under this field or above this field and click on it.
Selenium does not support such actions.
Selenium is designed to perform actions a real user can do with GUI.
As a user I can't add element into HTML web page.
I can click on element, get element text, scroll page etc.
Basically Selenium is used to testing. So, as per my suggestion there is no need to add anything from Selenium.
If there is no submit button, it is surely bug on your page.
So, we suggest you to check once again your page.
Selenium website link 🔗 https://www.selenium.dev/
The direct answer is No.
But through js you can update an attribute in Selenium. See below.
foo-text
you can basically update this foo-text to any other string, like :
driver.execute_script("document.getElementById('foo-id').innerHTML = '201';");
also, if you see we have id as an attribute that has an value foo-id, in case you want to update that id to someotherfoo-id, you can do as following :-
element = driver.find_element_by_class_name("foo-class");
driver.execute_script("arguments[0].setAttribute('id', 'someotherfoo-id')", element);
after this action, you must see the changes in UI. so basically you can do the modification like this.
I'm not that into Javascript but I think this could be achieved easily.
I've got a link on my page that sets a parameter (with PHP). That parameter is used to get how much posts to show. This works like a charm.
But now I want to scroll to the postition where the user clicked the link after the page reloads with the parameters. So the users doesn't have to scroll through the posts he already saw.
So here are the steps:
User clicks link to load more posts
Site gets reloaded with parameter (e.g. domain.com/?numberofposts=10)
Now the Site should scroll to the position the users was when he clicked the link
I was trying to achieve that with scrollTo etc but I cant get it working. My thaughts were to pass the scrollposition as an other parameter maybe?
Do someone know how to solve this? Thank you :)
By including an anchor tag within a post or page, you can place links in the body of your post which when clicked allow the reader to jump to another location on the page.
The anchor tag will consist of two HTML elements. First, you'll want to create the link.
If you are linking to a spot on the same page, the format of the link will be similar to:
Link Text
For example, if the text is "Read more about raptors!" then your HTML should look like this:
Read more about raptors!
The above anchor link only works when you are jumping to a specified spot on the same webpage. If you want a link to jump a specific location on a different page, you'll need to replace #anchor with the full URL for the page, similar to:
Link Text
The second part of an anchor tag is the actual anchor. The anchor should be placed at the beginning of the line where you want to start reading after you jump similar to:
<a name="anchor"></a>
Following our previous example, the anchor code will be:
<a name="raptors"></a>
Full tutorial here
You need to know where you have to scroll to.
So yes, you do need to store the scrollposition somewhere (or pass it as a parameter).
I have set up a chart with a lot of links and it really bugs me when it shows where the link goes in the bottom left hand side of the browser whenever you hover on a link, like so:
Is it possible to remove this? any method will do as long as I can hide/remove it (HTML, CSS, JS etc..)
The status bar highlighting happens only when you use an <a> element with a set href.
If you use pure JavaScript to open your link, and don't assign a href attribute, nothing will turn up in the status bar.
I don't know how much control you have over the chart html, but if it renders <a> tags there's not much you can do.
You could try running javascript after the chart is renderred to attach onclick event handlers manually to all <a> tags and set href = '#'.
I had a similar problem that led me to this thread. I figured I'd post my solution here rather than start a new thread about it.
I have a WordPress site with complex menus, and those menus had subheadings which the theme rendered as <a> links with empty href values. The site manager didn't want the bottom corner to display as a link if those were hovered over, since they didn't work has a link anyway.
<a href="#" class=" no_link" style="cursor: default;" onclick="Javascript: return false;">
I tried removing the "#" under href but it still showed the site's root url on hover.
Since the anchor tag's class list already included no_link as a class, I simply added the following jQuery to the global JavaScript file:
$("a.no_link").removeAttr("href");
Note that the intention was to simply remove a link's address on hover if it wasn't supposed to be a functional link anyway.
Refer this link here :
http://www.experts-exchange.com/Web_Development/Miscellaneous/Q_21278295.html
However , if the chart is not under your control, then this may not nbe the way
As suggested in the link :
Pink Floyd
You can also use jQuery to bind the mouseover event on these anchor links without editing individual <a>
I'm writing a small firefox addon to grab urls and send them to a site. What I want to do is be able to right click on a link (but not have to actually highlight it) and be able to click send and the links href value is grabbed and sent. The bit I'm having trouble with is detecting if the selected element is an anchor and grabbing it's href. Many thanks for any help given :)
nvm, found the solution at:
https://developer.mozilla.org/en/XUL/PopupGuide/Extensions#Determining_what_element_was_context_clicked
Hey so I set up a right click menu on my site you can see here
http://www.jaminproud.com
Everything works good except I want to add the abilty to open a link in a new tab. I have looked everywhere and cant find a solid answer for this. I would also need a way to make the menu so that option is only displayed while hovering over an anchor tag. Thanks in advance for any help.
P.S I dont need the actual code written that would be nice but rather just to be pointed in the direction Thanks.
There is now way to specify opening in a new tab yet, but when new browsers support CSS3 we will have the ability to tab link.
See: http://www.w3.org/TR/2004/WD-css3-hyperlinks-20040224/#target-new
For now, why not just use target="_new" ?
You need to save the element that was clicked on in the click event handler from the event object's target property. You can get the tag name using the element's nodeName property, and if it's an A element, you can get the URL using the href property.
Tabs are browser specific, so you probably just want to open it in a new window by specifying the target attribute in the link like so:
<a href='somewhere.html' target='_blank'>My Link</a>
Most tabbed browsers will let the user specify if they want it opened in a new tab or a new window when one of these type of links is clicked.